OLD | NEW |
(Empty) | |
| 1 dart_library.library('async_helper', null, /* Imports */[ |
| 2 "dart_runtime/dart", |
| 3 'dart/core', |
| 4 'dart/isolate' |
| 5 ], /* Lazy imports */[ |
| 6 ], function(exports, dart, core, isolate) { |
| 7 'use strict'; |
| 8 let dartx = dart.dartx; |
| 9 exports._initialized = false; |
| 10 exports._port = null; |
| 11 exports._asyncLevel = 0; |
| 12 function _buildException(msg) { |
| 13 return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your
test.`); |
| 14 } |
| 15 dart.fn(_buildException, core.Exception, [core.String]); |
| 16 function asyncStart() { |
| 17 if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) { |
| 18 dart.throw(_buildException('asyncStart() was called even though we are don
e ' + 'with testing.')); |
| 19 } |
| 20 if (!dart.notNull(exports._initialized)) { |
| 21 core.print('unittest-suite-wait-for-done'); |
| 22 exports._initialized = true; |
| 23 exports._port = isolate.ReceivePort.new(); |
| 24 } |
| 25 exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1; |
| 26 } |
| 27 dart.fn(asyncStart, dart.void, []); |
| 28 function asyncEnd() { |
| 29 if (dart.notNull(exports._asyncLevel) <= 0) { |
| 30 if (!dart.notNull(exports._initialized)) { |
| 31 dart.throw(_buildException('asyncEnd() was called before asyncStart().')
); |
| 32 } else { |
| 33 dart.throw(_buildException('asyncEnd() was called more often than ' + 'a
syncStart().')); |
| 34 } |
| 35 } |
| 36 exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1; |
| 37 if (exports._asyncLevel == 0) { |
| 38 exports._port.close(); |
| 39 exports._port = null; |
| 40 core.print('unittest-suite-success'); |
| 41 } |
| 42 } |
| 43 dart.fn(asyncEnd, dart.void, []); |
| 44 function asyncSuccess(_) { |
| 45 return asyncEnd(); |
| 46 } |
| 47 dart.fn(asyncSuccess, dart.void, [dart.dynamic]); |
| 48 function asyncTest(f) { |
| 49 asyncStart(); |
| 50 dart.dsend(f(), 'then', asyncSuccess); |
| 51 } |
| 52 dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]); |
| 53 // Exports: |
| 54 exports.asyncStart = asyncStart; |
| 55 exports.asyncEnd = asyncEnd; |
| 56 exports.asyncSuccess = asyncSuccess; |
| 57 exports.asyncTest = asyncTest; |
| 58 }); |
OLD | NEW |