diff --git a/lib/src/embedded/isolate_dispatcher.dart b/lib/src/embedded/isolate_dispatcher.dart index ebf62a3ed..1fd9877d9 100644 --- a/lib/src/embedded/isolate_dispatcher.dart +++ b/lib/src/embedded/isolate_dispatcher.dart @@ -33,7 +33,7 @@ class IsolateDispatcher { final _inactiveIsolates = {}; /// A map from active compilationIds to isolates running those compilations. - final _activeIsolates = {}; + final _activeIsolates = >{}; /// A pool controlling how many isolates (and thus concurrent compilations) /// may be live at once. @@ -54,8 +54,8 @@ class IsolateDispatcher { (compilationId, messageBuffer) = parsePacket(packet); if (compilationId != 0) { - var isolate = _activeIsolates[compilationId] ?? - await _getIsolate(compilationId); + var isolate = await _activeIsolates.putIfAbsent( + compilationId, () => _getIsolate(compilationId!)); try { isolate.send(packet); return; @@ -108,7 +108,6 @@ class IsolateDispatcher { _allIsolates.add(isolate); } - _activeIsolates[compilationId] = isolate; isolate.checkOut().listen(_channel.sink.add, onError: (Object error, StackTrace stackTrace) { if (error is ProtocolError) {