Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(952)

Unified Diff: runtime/lib/lib_prefix.dart

Issue 328923002: Lazy loading of deferred libraries (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/lib/mirrors.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/lib_prefix.dart
===================================================================
--- runtime/lib/lib_prefix.dart (revision 37317)
+++ runtime/lib/lib_prefix.dart (working copy)
@@ -6,19 +6,47 @@
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 port = new RawReceivePort();
- port.handler = (_) {
- this._load();
- completer.complete(true);
- port.close();
- };
- port.sendPort.send(1);
+ var completer = _outstandingLoadRequests[this];
+ if (completer != null) {
+ return completer.future;
+ }
+ completer = new Completer<bool>();
+ _outstandingLoadRequests[this] = completer;
+ Timer.run(() {
+ var hasCompleted = this._load();
+ // Loading can complete immediately, for example when the same
+ // library has been loaded eagerly or through another deferred
+ // prefix. If that is the case, we must invalidate the dependent
+ // code and complete the future now since there will be no callback
+ // from the VM.
+ if (hasCompleted) {
+ _invalidateDependentCode();
+ completer.complete(true);
+ _outstandingLoadRequests.remove(this);
+ }
+ });
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();
+}
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/lib/mirrors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698