Chromium Code Reviews| Index: test/codegen/async_helper.dart |
| diff --git a/test/codegen/async_helper.dart b/test/codegen/async_helper.dart |
| index 37496bcb76bda9156c55f57b6accd2ec6b35895f..0072fb20f696c7f78ea502018a2bb9429e8a41bb 100644 |
| --- a/test/codegen/async_helper.dart |
| +++ b/test/codegen/async_helper.dart |
| @@ -23,20 +23,27 @@ |
| library async_helper; |
| -// TODO(kustermann): This is problematic because we rely on a working |
| -// 'dart:isolate' (i.e. it is in particular problematic with dart2js). |
| -// It would be nice if we could use a different mechanism for different |
| -// runtimes. |
| -import 'dart:isolate'; |
| - |
| bool _initialized = false; |
| -ReceivePort _port = null; |
| +Function _onAsyncEnd; |
|
vsm
2015/08/19 15:02:35
Perhaps give this a signature / typedef to avoid t
Jennifer Messerly
2015/08/19 15:34:44
Done.
fwiw, this method won't really appear on st
|
| + |
| int _asyncLevel = 0; |
| Exception _buildException(String msg) { |
| return new Exception('Fatal: $msg. This is most likely a bug in your test.'); |
| } |
| +/// Implementation method called from language_tests.js. |
| +/// Registers the callback that will be used complete the test. |
| +void asyncTestInitialize(void callback()) { |
| + _asyncLevel = 0; |
| + _initialized = false; |
| + _onAsyncEnd = callback; |
| +} |
| + |
| +/// Implementation method called from language_tests.js. |
| +/// Returns true if an asyncTest was started. |
| +bool get asyncTestStarted => _initialized; |
| + |
| /// Call this method before an asynchronous test is created. |
| void asyncStart() { |
| if (_initialized && _asyncLevel == 0) { |
| @@ -44,9 +51,14 @@ void asyncStart() { |
| 'with testing.'); |
| } |
| if (!_initialized) { |
| + if (_onAsyncEnd == null) { |
| + throw _buildException( |
| + 'asyncStart() was called before asyncTestInitialize()'); |
| + } |
| + |
| print('unittest-suite-wait-for-done'); |
| _initialized = true; |
| - _port = new ReceivePort(); |
| + |
| } |
| _asyncLevel++; |
| } |
| @@ -63,8 +75,9 @@ void asyncEnd() { |
| } |
| _asyncLevel--; |
| if (_asyncLevel == 0) { |
| - _port.close(); |
| - _port = null; |
| + var callback = _onAsyncEnd; |
| + _onAsyncEnd = null; |
| + callback(); |
| print('unittest-suite-success'); |
| } |
| } |