Chromium Code Reviews| Index: runtime/lib/lib_prefix.dart |
| =================================================================== |
| --- runtime/lib/lib_prefix.dart (revision 37209) |
| +++ runtime/lib/lib_prefix.dart (working copy) |
| @@ -6,19 +6,45 @@ |
| import "dart:isolate"; |
| // This type corresponds to the VM-internal class LibraryPrefix. |
| - |
| class _LibraryPrefix { |
| - _load() native "LibraryPrefix_load"; |
| + bool _load() native "LibraryPrefix_load"; |
| + |
| + void _invalidateDependentCode() |
| + native "LibraryPrefix_invalidateDependentCode"; |
| + |
| loadLibrary() { |
| - var completer = new Completer<bool>(); |
| + var completer = _outstandingLoadRequests[this]; |
| + if (completer != null) { |
| + return completer.future; |
| + } |
| + completer = new Completer<bool>(); |
| + _outstandingLoadRequests[this] = completer; |
| var port = new RawReceivePort(); |
|
Ivan Posva
2014/06/12 23:05:11
We can simplify this with Timer.run(() {...}).
hausner
2014/06/12 23:54:37
Done.
|
| port.handler = (_) { |
| - this._load(); |
| - completer.complete(true); |
| + var hasCompleted = this._load(); |
| + if (hasCompleted) { |
| + _invalidateDependentCode(); |
|
Ivan Posva
2014/06/12 23:05:11
How about a comment explaining why this is needed?
hausner
2014/06/12 23:54:37
Done.
|
| + completer.complete(true); |
| + _outstandingLoadRequests.remove(this); |
| + } |
| port.close(); |
| }; |
| port.sendPort.send(1); |
| return completer.future; |
| } |
| } |
| + |
| +var _outstandingLoadRequests = new Map<_LibraryPrefix, Completer>(); |
| + |
| + |
| +// Called from the VM when all outstanding load requests have |
| +// finished. |
| +_completeDeferredLoads() { |
| + var lenghth = _outstandingLoadRequests; |
| + _outstandingLoadRequests.forEach((prefix, completer) { |
| + prefix._invalidateDependentCode(); |
| + completer.complete(true); |
| + }); |
| + _outstandingLoadRequests.clear(); |
| +} |