Chromium Code Reviews| Index: pkg/code_transformers/lib/src/resolver_impl.dart |
| diff --git a/pkg/code_transformers/lib/src/resolver_impl.dart b/pkg/code_transformers/lib/src/resolver_impl.dart |
| index fe9f6d951fce11abfe3b0d41e2b2051a6e6bebc2..9512f0f21d1fab9478cf65233c00db856d6e1c33 100644 |
| --- a/pkg/code_transformers/lib/src/resolver_impl.dart |
| +++ b/pkg/code_transformers/lib/src/resolver_impl.dart |
| @@ -46,6 +46,12 @@ class ResolverImpl implements Resolver { |
| /// The currently resolved library, or null if unresolved. |
| LibraryElement _entryLibrary; |
| + /// Future indicating when this resolver is done in the current phase. |
| + Future _lastPhaseComplete = new Future.value(); |
| + |
| + /// Completer for wrapping up the current phase. |
| + Completer _currentPhaseComplete; |
| + |
| /// Handler for all Dart SDK (dart:) sources. |
| DirectoryBasedDartSdk _dartSdk; |
| @@ -73,19 +79,38 @@ class ResolverImpl implements Resolver { |
| LibraryElement get entryLibrary => _entryLibrary; |
| + Future<Resolver> resolve(Transform transform) { |
| + // Can only have one resolve in progress at a time, so chain the current |
| + // resolution to be after the last one. |
| + var phaseComplete = new Completer(); |
| + var future = _lastPhaseComplete.then((_) { |
| + _currentPhaseComplete = phaseComplete; |
| - /// Update the status of all the sources referenced by the entryPoint and |
| - /// update the resolved library. |
| - /// |
| - /// This will be invoked automatically by [ResolverTransformer]. Only one |
| - /// transformer may update this at a time. |
| - Future updateSources(Transform transform) { |
| + return _performResolve(transform); |
| + }).then((_) { |
| + return this; |
| + }); |
|
Siggi Cherem (dart-lang)
2014/02/27 18:20:41
style nit: use (_) => this, maybe fold into the pr
blois
2014/02/27 23:47:17
Done.
|
| + // Advance the lastPhaseComplete to be done when this phase is all done. |
| + _lastPhaseComplete = phaseComplete.future; |
| + return future; |
| + } |
| + |
| + void release() { |
| + if (_currentPhaseComplete == null) { |
| + throw new StateError('Releasing without current lock.'); |
| + } |
| + _currentPhaseComplete.complete(null); |
| + _currentPhaseComplete = null; |
| + |
| + // Clear out the entry lib since it should not be referenced after release. |
| + _entryLibrary = null; |
| + } |
| + |
| + Future _performResolve(Transform transform) { |
| if (_currentTransform != null) { |
| throw new StateError('Cannot be accessed by concurrent transforms'); |
| } |
| _currentTransform = transform; |
| - // Clear this out and update once all asset changes have been processed. |
| - _entryLibrary = null; |
| // Basic approach is to start at the first file, update it's contents |
| // and see if it changed, then walk all files accessed by it. |