jicang / healywatch_reactive

ff
0 stars 3 forks source link

What are the purposes of these delays? #73

Closed BradKwon closed 2 years ago

BradKwon commented 2 years ago

What are the purposes of these delays? If it is optimizable, please reduce the delay as we don't need it if it is unnecessary. And please also add a comment on the line why we need this delay.

1) 1s delay at line 531 in bluetooth_connection_util.dart

await Future.delayed(Duration(seconds: 1));

if (_connection != null) {
  log(
    'already connecting to device: $device',
    name: loggerName,
    time: DateTime.now(),
  );
  return;
}

2) 1s delay at line 665 in bluetooth_connection_util.dart

  await Future.delayed(Duration(seconds: 1));
  await _connection?.cancel();
  _connection = null;

3) 2s delay at line 733 in bluetooth_connection_util.dart

await _connection?.cancel();
_connection = null;
await Future.delayed(Duration(seconds: 2));
if (bleManager.status == BleStatus.poweredOff ||
    isFirmwareUpdating ||
    device == null) {
  return null;
}
Danny23523 commented 2 years ago

Hi, Brad, the purpose for the delay because if connect directly, the probability of error will be high, if add this delay, it will be more stable, which is fixed by Alexander, you can also confirm with him.

BradKwon commented 2 years ago

Thanks! Then we will contact him for the further info.