Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
wait for position port to be set up
Browse files Browse the repository at this point in the history
  • Loading branch information
yringler committed Jun 19, 2020
1 parent f9c0ba5 commit 2117440
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lib/position-manager/position-data-manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class HivePositionDataManager extends IPositionDataManager {
Future<void> close() async {
try {
await positionHive.close();
}
catch (err) {
} catch (err) {
print(err);
}
}
Expand Down Expand Up @@ -149,9 +148,30 @@ class AudioServicePositionManager extends IPositionDataManager {

@override
Future<List<Position>> getPositions(List<String> ids) async {
final sendPort =
IsolateNameServer.lookupPortByName(PositionedAudioTask.SendPortID);

var sendPort;

// Wait for the send port to be available.
await Future.doWhile(() async {
sendPort =
IsolateNameServer.lookupPortByName(PositionedAudioTask.SendPortID);

if (sendPort != null) {
return false;
}

await Future.delayed(Duration(milliseconds: 100));
// Try again...
return true;
}).timeout(Duration(seconds: 2),
onTimeout: () async {
// If I make this a lambda, it's an error. This is a bit clumsy - dart
// should be able to do better.
print("error: timeout for port");
return false;
});

assert(sendPort != null);

if (sendPort == null) {
return null;
}
Expand Down

0 comments on commit 2117440

Please sign in to comment.