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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:async"; 5 import "dart:async";
6 import "dart:isolate"; 6 import "dart:isolate";
7 7
8 // This type corresponds to the VM-internal class LibraryPrefix. 8 // This type corresponds to the VM-internal class LibraryPrefix.
9 class _LibraryPrefix {
9 10
10 class _LibraryPrefix { 11 bool _load() native "LibraryPrefix_load";
11 _load() native "LibraryPrefix_load"; 12
13 void _invalidateDependentCode()
14 native "LibraryPrefix_invalidateDependentCode";
12 15
13 loadLibrary() { 16 loadLibrary() {
14 var completer = new Completer<bool>(); 17 var completer = _outstandingLoadRequests[this];
18 if (completer != null) {
19 return completer.future;
20 }
21 completer = new Completer<bool>();
22 _outstandingLoadRequests[this] = completer;
15 var port = new RawReceivePort(); 23 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.
16 port.handler = (_) { 24 port.handler = (_) {
17 this._load(); 25 var hasCompleted = this._load();
18 completer.complete(true); 26 if (hasCompleted) {
27 _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.
28 completer.complete(true);
29 _outstandingLoadRequests.remove(this);
30 }
19 port.close(); 31 port.close();
20 }; 32 };
21 port.sendPort.send(1); 33 port.sendPort.send(1);
22 return completer.future; 34 return completer.future;
23 } 35 }
24 } 36 }
37
38 var _outstandingLoadRequests = new Map<_LibraryPrefix, Completer>();
39
40
41 // Called from the VM when all outstanding load requests have
42 // finished.
43 _completeDeferredLoads() {
44 var lenghth = _outstandingLoadRequests;
45 _outstandingLoadRequests.forEach((prefix, completer) {
46 prefix._invalidateDependentCode();
47 completer.complete(true);
48 });
49 _outstandingLoadRequests.clear();
50 }
OLDNEW
« runtime/bin/dartutils.cc ('K') | « runtime/bin/dartutils.cc ('k') | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698