Chromium Code Reviews| Index: sdk/lib/async/zone.dart |
| diff --git a/sdk/lib/async/zone.dart b/sdk/lib/async/zone.dart |
| index 5cc4d88ef71082771c22389db2fb77be48485faa..b38906994f825b9a59786ae72e93e75300ce2e68 100644 |
| --- a/sdk/lib/async/zone.dart |
| +++ b/sdk/lib/async/zone.dart |
| @@ -8,6 +8,10 @@ typedef dynamic ZoneCallback(); |
| typedef dynamic ZoneUnaryCallback(arg); |
| typedef dynamic ZoneBinaryCallback(arg1, arg2); |
| +typedef Task TaskCreate(TaskSpecification taskSpecification, Zone zone); |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Which zone are we passing to the create function?
floitsch
2016/04/05 20:07:17
The zone in which the task should execute, when th
|
| +typedef void TaskCancel(Task task, Zone zone); |
| +typedef void TaskRun(Task task, Object arg, Zone zone); |
| + |
| typedef dynamic HandleUncaughtErrorHandler( |
| Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); |
| typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); |
| @@ -23,19 +27,27 @@ typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( |
| Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); |
| typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, |
| Zone zone, Object error, StackTrace stackTrace); |
| +typedef Task CreateTaskHandler(Zone self, ZoneDelegate parent, Zone zone, |
| + TaskSpecification taskSpecification, TaskCreate schedule); |
| +typedef void CancelTaskHandler(Zone self, ZoneDelegate parent, Zone zone, |
| + Task task, TaskCancel cancel); |
| +typedef void RunTaskHandler(Zone self, ZoneDelegate parent, Zone zone, |
| + Task task, Object arg1, TaskRun run); |
| typedef void ScheduleMicrotaskHandler( |
| Zone self, ZoneDelegate parent, Zone zone, f()); |
| -typedef Timer CreateTimerHandler( |
| - Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); |
| -typedef Timer CreatePeriodicTimerHandler( |
| - Zone self, ZoneDelegate parent, Zone zone, |
| - Duration period, void f(Timer timer)); |
| typedef void PrintHandler( |
| Zone self, ZoneDelegate parent, Zone zone, String line); |
| typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
| ZoneSpecification specification, |
| Map zoneValues); |
| +// Typedefs for deprecated methods. |
| +typedef Timer CreateTimerHandler( |
| + Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); |
| +typedef Timer CreatePeriodicTimerHandler( |
| + Zone self, ZoneDelegate parent, Zone zone, |
| + Duration period, void f(Timer timer)); |
| + |
| /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ |
| class AsyncError implements Error { |
| final error; |
| @@ -46,6 +58,116 @@ class AsyncError implements Error { |
| String toString() => '$error'; |
| } |
| +/// A token-like object that represents an asynchronous operation. |
| +/// |
| +/// Tasks are always invoked by the event loop. For example, a [Timer] contains |
| +/// a [Task] object that represents the scheduled operation. |
| +/// |
| +/// Tasks can be thought as advanced tokens (containing the task specification), |
| +/// and aren't necessarily distributed to users. |
| +abstract class Task { |
| + /// The specification that was used to create this task. |
| + TaskSpecification get specification; |
| + |
| + /// The zone in which the tasks has been created and should run whenever the |
| + /// event loop runs the task. |
| + Zone get zone; |
|
floitsch
2016/03/31 19:18:01
We could remove this field.
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Agree. I generally prefer not to leak zones, so co
floitsch
2016/04/05 20:07:17
The thing is, that the task needs to keep track of
|
| +} |
| + |
| +abstract class TaskSpecification { |
| + /// Description of the task. |
| + /// |
| + /// This string is unused by the root-zone, but might be used for debugging, |
| + /// and testing. As such, it should be relatively unique in its category. |
| + String get description; |
| + |
| + /// Whether this specification is for an event task. |
| + /// |
| + /// Event tasks are macro tasks with specific expectations. In particular, |
| + /// they may never run, or run multiple times. |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
That's rather the absence of specific expectations
floitsch
2016/04/05 20:07:17
Fair enough. It might be more interesting to have
|
| + /// |
| + /// Event tasks are never [isOneShot]. |
| + /// |
| + /// Event tasks imply [isMacroTask]. |
| + bool get isEventTask; |
| + |
| + /// Whether this specification is for a macro task. |
| + /// |
| + /// Macro tasks are triggered from the event loop and start a new micro task |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
"triggered from the event loop" is vague (as in: I
floitsch
2016/04/05 20:07:16
Done.
|
| + /// loop. |
| + bool get isMacroTask; |
| + |
| + /// Whether the scheduled task triggers at most once. |
| + /// |
| + /// If the task is not a one-shot task, it must be canceled. |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
"must be canceled" may be too strong. You can prob
floitsch
2016/04/05 20:07:16
Done.
|
| + bool get isOneShot; |
| +} |
| + |
| +class _TimerTaskWrapper implements Timer { |
| + final TimerTask _task; |
| + |
| + _TimerTaskWrapper(this._task); |
| + |
| + static _cancel(TimerTask task, Zone zone) { |
| + task.timer.cancel(); |
| + } |
| + |
| + void cancel() { |
| + _task.zone.cancelTask(_task, _cancel); |
| + } |
| + |
| + bool get isActive => _task.timer.isActive; |
| +} |
| + |
| +abstract class TimerTask implements Task { |
| + final TaskSpecification specification; |
| + final Zone zone; |
| + /// The native timer. |
| + final Timer timer; |
| + |
| + TimerTask(this.timer, this.specification, this.zone); |
| +} |
| + |
| +class SingleShotTimerTask extends TimerTask { |
| + final ZoneCallback callback; |
| + |
| + SingleShotTimerTask(Timer timer, this.callback, |
| + TaskSpecification specification, Zone zone) |
| + : super(timer, specification, zone); |
| +} |
| + |
| +class PeriodicTimerTask extends TimerTask { |
| + final ZoneUnaryCallback callback; |
| + |
| + PeriodicTimerTask(Timer timer, this.callback, |
| + TaskSpecification specification, Zone zone) |
| + : super(timer, specification, zone); |
| +} |
| + |
| +class SingleShotTimerTaskSpecification implements TaskSpecification { |
| + String get description => "Timer"; |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Maybe just make this the "toString" of the task-sp
floitsch
2016/04/05 20:07:16
This is the identifier that delegates use to inter
|
| + bool get isOneShot => true; |
| + bool get isEventTask => false; |
| + bool get isMacroTask => true; |
| + |
| + final Duration duration; |
| + final ZoneCallback callback; |
| + |
| + SingleShotTimerTaskSpecification(this.duration, void this.callback()); |
| +} |
| + |
| +class PeriodicTimerTaskSpecification implements TaskSpecification { |
| + String get description => "Periodic Timer"; |
| + bool get isOneShot => false; |
| + bool get isEventTask => false; |
| + bool get isMacroTask => true; |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
I still prefer putting getters after the construct
floitsch
2016/04/05 20:07:16
Done.
|
| + |
| + final Duration duration; |
| + final ZoneUnaryCallback callback; |
| + |
| + PeriodicTimerTaskSpecification( |
| + this.duration, void this.callback(Timer timer)); |
| +} |
| class _ZoneFunction { |
| final _Zone zone; |
| @@ -94,13 +216,23 @@ abstract class ZoneSpecification { |
| Object error, StackTrace stackTrace), |
| void scheduleMicrotask( |
| Zone self, ZoneDelegate parent, Zone zone, f()), |
| + Task createTask(Zone self, ZoneDelegate parent, Zone zone, |
| + TaskSpecification taskSpecification, TaskCreate create), |
|
Lasse Reichstein Nielsen
2016/04/01 21:26:35
I'm still not sure I think the create argument is
floitsch
2016/04/05 20:07:16
I strongly disagree.
The root-zone must be able to
|
| + void runTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + Object arg, TaskRun run), |
| + void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + TaskCancel cancel), |
| + |
| + void print(Zone self, ZoneDelegate parent, Zone zone, String line), |
| + Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
| + ZoneSpecification specification, Map zoneValues), |
| + |
| + @deprecated |
| Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
| Duration duration, void f()), |
| + @deprecated |
| Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
| - Duration period, void f(Timer timer)), |
| - void print(Zone self, ZoneDelegate parent, Zone zone, String line), |
| - Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
| - ZoneSpecification specification, Map zoneValues) |
| + Duration period, void f(Timer timer)) |
| }) = _ZoneSpecification; |
| /** |
| @@ -125,14 +257,25 @@ abstract class ZoneSpecification { |
| Object error, StackTrace stackTrace), |
| void scheduleMicrotask( |
| Zone self, ZoneDelegate parent, Zone zone, f()): null, |
| - Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
| - Duration duration, void f()): null, |
| - Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
| - Duration period, void f(Timer timer)): null, |
| + |
| + Task createTask(Zone self, ZoneDelegate parent, Zone zone, |
| + TaskSpecification taskSpecification, TaskCreate create): null, |
| + void runTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + TaskRun run): null, |
| + void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + TaskCancel cancel): null, |
| + |
| void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, |
| Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
| ZoneSpecification specification, |
| - Map zoneValues): null |
| + Map zoneValues): null, |
| + |
| + @deprecated |
| + Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
| + Duration duration, void f()): null, |
| + @deprecated |
| + Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
| + Duration period, void f(Timer timer)): null |
| }) { |
| return new ZoneSpecification( |
| handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, |
| @@ -145,11 +288,15 @@ abstract class ZoneSpecification { |
| registerBinaryCallback: registerBinaryCallback ?? |
| other.registerBinaryCallback, |
| errorCallback: errorCallback ?? other.errorCallback, |
| + |
| + createTask: createTask ?? other.createTask, |
| + runTask: runTask ?? other.runTask, |
| + cancelTask: cancelTask ?? other.cancelTask, |
| + print : print ?? other.print, |
| + fork: fork ?? other.fork, |
| scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, |
| createTimer : createTimer ?? other.createTimer, |
| - createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer, |
| - print : print ?? other.print, |
| - fork: fork ?? other.fork); |
| + createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer); |
| } |
| HandleUncaughtErrorHandler get handleUncaughtError; |
| @@ -161,10 +308,16 @@ abstract class ZoneSpecification { |
| RegisterBinaryCallbackHandler get registerBinaryCallback; |
| ErrorCallbackHandler get errorCallback; |
| ScheduleMicrotaskHandler get scheduleMicrotask; |
| - CreateTimerHandler get createTimer; |
| - CreatePeriodicTimerHandler get createPeriodicTimer; |
| + CreateTaskHandler get createTask; |
| + RunTaskHandler get runTask; |
| + CancelTaskHandler get cancelTask; |
| PrintHandler get print; |
| ForkHandler get fork; |
| + |
| + @deprecated |
| + CreateTimerHandler get createTimer; |
| + @deprecated |
| + CreatePeriodicTimerHandler get createPeriodicTimer; |
| } |
| /** |
| @@ -185,10 +338,15 @@ class _ZoneSpecification implements ZoneSpecification { |
| this.registerBinaryCallback: null, |
| this.errorCallback: null, |
| this.scheduleMicrotask: null, |
| - this.createTimer: null, |
| - this.createPeriodicTimer: null, |
| + this.createTask: null, |
| + this.runTask: null, |
| + this.cancelTask: null, |
| this.print: null, |
| - this.fork: null |
| + this.fork: null, |
| + @deprecated |
| + this.createTimer: null, |
| + @deprecated |
| + this.createPeriodicTimer: null |
| }); |
| final HandleUncaughtErrorHandler handleUncaughtError; |
| @@ -200,10 +358,16 @@ class _ZoneSpecification implements ZoneSpecification { |
| final RegisterBinaryCallbackHandler registerBinaryCallback; |
| final ErrorCallbackHandler errorCallback; |
| final ScheduleMicrotaskHandler scheduleMicrotask; |
| - final CreateTimerHandler createTimer; |
| - final CreatePeriodicTimerHandler createPeriodicTimer; |
| + final CreateTaskHandler createTask; |
| + final RunTaskHandler runTask; |
| + final CancelTaskHandler cancelTask; |
| final PrintHandler print; |
| final ForkHandler fork; |
| + |
| + @deprecated |
| + final CreateTimerHandler createTimer; |
| + @deprecated |
| + final CreatePeriodicTimerHandler createPeriodicTimer; |
| } |
| /** |
| @@ -226,10 +390,16 @@ abstract class ZoneDelegate { |
| ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); |
| AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); |
| void scheduleMicrotask(Zone zone, f()); |
| - Timer createTimer(Zone zone, Duration duration, void f()); |
| - Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); |
| + Task createTask(Zone zone, TaskSpecification task, TaskCreate schedule); |
| + void runTask(Zone zone, Task task, Object arg, TaskRun run); |
| + void cancelTask(Zone zone, Task task, TaskCancel cancel); |
| void print(Zone zone, String line); |
| Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); |
| + |
| + @deprecated |
| + Timer createTimer(Zone zone, Duration duration, void f()); |
| + @deprecated |
| + Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); |
| } |
| /** |
| @@ -413,14 +583,20 @@ abstract class Zone { |
| */ |
| void scheduleMicrotask(void f()); |
| + Task createTask(TaskSpecification task, TaskCreate create); |
| + void runTask(Task task, Object arg1, TaskRun run); |
| + void cancelTask(Task task, TaskCancel cancel); |
| + |
| /** |
| * Creates a Timer where the callback is executed in this zone. |
| */ |
| + @deprecated |
| Timer createTimer(Duration duration, void callback()); |
| /** |
| * Creates a periodic Timer where the callback is executed in this zone. |
| */ |
| + @deprecated |
| Timer createPeriodicTimer(Duration period, void callback(Timer timer)); |
| /** |
| @@ -543,18 +719,25 @@ class _ZoneDelegate implements ZoneDelegate { |
| handler(implZone, _parentDelegate(implZone), zone, f); |
| } |
| - Timer createTimer(Zone zone, Duration duration, void f()) { |
| - _ZoneFunction implementation = _delegationTarget._createTimer; |
| + Task createTask(Zone zone, TaskSpecification task, TaskCreate create) { |
| + _ZoneFunction implementation = _delegationTarget._createTask; |
| _Zone implZone = implementation.zone; |
| - CreateTimerHandler handler = implementation.function; |
| - return handler(implZone, _parentDelegate(implZone), zone, duration, f); |
| + CreateTaskHandler handler = implementation.function; |
| + return handler(implZone, _parentDelegate(implZone), zone, task, create); |
| } |
| - Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
| - _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; |
| + void runTask(Zone zone, Task task, Object arg, TaskRun run) { |
| + _ZoneFunction implementation = _delegationTarget._runTask; |
| _Zone implZone = implementation.zone; |
| - CreatePeriodicTimerHandler handler = implementation.function; |
| - return handler(implZone, _parentDelegate(implZone), zone, period, f); |
| + RunTaskHandler handler = implementation.function; |
| + handler(implZone, _parentDelegate(implZone), zone, task, arg, run); |
| + } |
| + |
| + void cancelTask(Zone zone, Task task, TaskCancel cancel) { |
| + _ZoneFunction implementation = _delegationTarget._cancelTask; |
| + _Zone implZone = implementation.zone; |
| + CancelTaskHandler handler = implementation.function; |
| + handler(implZone, _parentDelegate(implZone), zone, task, cancel); |
| } |
| void print(Zone zone, String line) { |
| @@ -572,6 +755,22 @@ class _ZoneDelegate implements ZoneDelegate { |
| return handler( |
| implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
| } |
| + |
| + @deprecated |
| + Timer createTimer(Zone zone, Duration duration, void f()) { |
| + _ZoneFunction implementation = _delegationTarget._createTimer; |
| + _Zone implZone = implementation.zone; |
| + CreateTimerHandler handler = implementation.function; |
| + return handler(implZone, _parentDelegate(implZone), zone, duration, f); |
| + } |
| + |
| + @deprecated |
| + Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
| + _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; |
| + _Zone implZone = implementation.zone; |
| + CreatePeriodicTimerHandler handler = implementation.function; |
| + return handler(implZone, _parentDelegate(implZone), zone, period, f); |
| + } |
| } |
| @@ -589,11 +788,18 @@ abstract class _Zone implements Zone { |
| _ZoneFunction get _registerBinaryCallback; |
| _ZoneFunction get _errorCallback; |
| _ZoneFunction get _scheduleMicrotask; |
| - _ZoneFunction get _createTimer; |
| - _ZoneFunction get _createPeriodicTimer; |
| + _ZoneFunction get _createTask; |
| + _ZoneFunction get _runTask; |
| + _ZoneFunction get _cancelTask; |
| _ZoneFunction get _print; |
| _ZoneFunction get _fork; |
| _ZoneFunction get _handleUncaughtError; |
| + |
| + @deprecated |
| + _ZoneFunction get _createTimer; |
| + @deprecated |
| + _ZoneFunction get _createPeriodicTimer; |
| + |
| _Zone get parent; |
| _ZoneDelegate get _delegate; |
| Map get _map; |
| @@ -615,12 +821,18 @@ class _CustomZone extends _Zone { |
| _ZoneFunction _registerBinaryCallback; |
| _ZoneFunction _errorCallback; |
| _ZoneFunction _scheduleMicrotask; |
| - _ZoneFunction _createTimer; |
| - _ZoneFunction _createPeriodicTimer; |
| + _ZoneFunction _createTask; |
| + _ZoneFunction _runTask; |
| + _ZoneFunction _cancelTask; |
| _ZoneFunction _print; |
| _ZoneFunction _fork; |
| _ZoneFunction _handleUncaughtError; |
| + @deprecated |
| + _ZoneFunction _createTimer; |
| + @deprecated |
| + _ZoneFunction _createPeriodicTimer; |
| + |
| // A cached delegate to this zone. |
| ZoneDelegate _delegateCache; |
| @@ -666,12 +878,15 @@ class _CustomZone extends _Zone { |
| _scheduleMicrotask = (specification.scheduleMicrotask != null) |
| ? new _ZoneFunction(this, specification.scheduleMicrotask) |
| : parent._scheduleMicrotask; |
| - _createTimer = (specification.createTimer != null) |
| - ? new _ZoneFunction(this, specification.createTimer) |
| - : parent._createTimer; |
| - _createPeriodicTimer = (specification.createPeriodicTimer != null) |
| - ? new _ZoneFunction(this, specification.createPeriodicTimer) |
| - : parent._createPeriodicTimer; |
| + _createTask = (specification.createTask != null) |
| + ? new _ZoneFunction(this, specification.createTask) |
| + : parent._createTask; |
| + _runTask = (specification.runTask != null) |
| + ? new _ZoneFunction(this, specification.runTask) |
| + : parent._runTask; |
| + _cancelTask = (specification.cancelTask != null) |
| + ? new _ZoneFunction(this, specification.runTask) |
| + : parent._cancelTask; |
| _print = (specification.print != null) |
| ? new _ZoneFunction(this, specification.print) |
| : parent._print; |
| @@ -681,6 +896,14 @@ class _CustomZone extends _Zone { |
| _handleUncaughtError = (specification.handleUncaughtError != null) |
| ? new _ZoneFunction(this, specification.handleUncaughtError) |
| : parent._handleUncaughtError; |
| + |
| + // Deprecated fields. |
| + _createTimer = (specification.createTimer != null) |
| + ? new _ZoneFunction(this, specification.createTimer) |
| + : parent._createTimer; |
| + _createPeriodicTimer = (specification.createPeriodicTimer != null) |
| + ? new _ZoneFunction(this, specification.createPeriodicTimer) |
| + : parent._createPeriodicTimer; |
| } |
| /** |
| @@ -847,9 +1070,39 @@ class _CustomZone extends _Zone { |
| assert(implementation != null); |
| ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| ScheduleMicrotaskHandler handler = implementation.function; |
| - return handler(implementation.zone, parentDelegate, this, f); |
| + handler(implementation.zone, parentDelegate, this, f); |
| + } |
| + |
| + Task createTask(TaskSpecification task, TaskCreate create) { |
| + _ZoneFunction implementation = this._createTask; |
| + ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| + CreateTaskHandler handler = implementation.function; |
| + return handler(implementation.zone, parentDelegate, this, task, create); |
| + } |
| + |
| + void runTask(Task task, Object arg1, TaskRun run) { |
| + _ZoneFunction implementation = this._runTask; |
| + ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| + RunTaskHandler handler = implementation.function; |
| + handler(implementation.zone, parentDelegate, this, task, arg1, run); |
| } |
| + void cancelTask(Task task, TaskCancel cancel) { |
| + _ZoneFunction implementation = this._cancelTask; |
| + ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| + CancelTaskHandler handler = implementation.function; |
| + handler(implementation.zone, parentDelegate, this, task, cancel); |
| + } |
| + |
| + void print(String line) { |
| + _ZoneFunction implementation = this._print; |
| + assert(implementation != null); |
| + ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| + PrintHandler handler = implementation.function; |
| + return handler(implementation.zone, parentDelegate, this, line); |
| + } |
| + |
| + @deprecated |
| Timer createTimer(Duration duration, void f()) { |
| _ZoneFunction implementation = this._createTimer; |
| assert(implementation != null); |
| @@ -858,6 +1111,7 @@ class _CustomZone extends _Zone { |
| return handler(implementation.zone, parentDelegate, this, duration, f); |
| } |
| + @deprecated |
| Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
| _ZoneFunction implementation = this._createPeriodicTimer; |
| assert(implementation != null); |
| @@ -866,14 +1120,6 @@ class _CustomZone extends _Zone { |
| return handler( |
| implementation.zone, parentDelegate, this, duration, f); |
| } |
| - |
| - void print(String line) { |
| - _ZoneFunction implementation = this._print; |
| - assert(implementation != null); |
| - ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| - PrintHandler handler = implementation.function; |
| - return handler(implementation.zone, parentDelegate, this, line); |
| - } |
| } |
| void _rootHandleUncaughtError( |
| @@ -949,6 +1195,28 @@ void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { |
| _scheduleAsyncCallback(f); |
| } |
| +Task _rootcreateTask(Zone self, ZoneDelegate parent, Zone zone, |
| + TaskSpecification taskSpecification, TaskCreate create) { |
| + return create(taskSpecification, zone); |
| +} |
| + |
| +void _rootRunTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + Object arg, TaskRun run) { |
| + if (Zone._current == zone) run(task, arg, zone); |
| + |
| + Zone old = Zone._enter(zone); |
| + try { |
| + run(task, arg, zone); |
| + } finally { |
| + Zone._leave(old); |
| + } |
| +} |
| + |
| +void _rootCancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
| + TaskCancel cancel) { |
| + cancel(task, zone); |
| +} |
| + |
| Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, |
| Duration duration, void callback()) { |
| if (!identical(_ROOT_ZONE, zone)) { |
| @@ -1020,10 +1288,12 @@ class _RootZone extends _Zone { |
| const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); |
| _ZoneFunction get _scheduleMicrotask => |
| const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); |
| - _ZoneFunction get _createTimer => |
| - const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); |
| - _ZoneFunction get _createPeriodicTimer => |
| - const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); |
| + _ZoneFunction get _createTask => |
| + const _ZoneFunction(_ROOT_ZONE, _rootcreateTask); |
| + _ZoneFunction get _runTask => |
| + const _ZoneFunction(_ROOT_ZONE, _rootRunTask); |
| + _ZoneFunction get _cancelTask => |
| + const _ZoneFunction(_ROOT_ZONE, _rootCancelTask); |
| _ZoneFunction get _print => |
| const _ZoneFunction(_ROOT_ZONE, _rootPrint); |
| _ZoneFunction get _fork => |
| @@ -1031,6 +1301,13 @@ class _RootZone extends _Zone { |
| _ZoneFunction get _handleUncaughtError => |
| const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); |
| + @deprecated |
| + _ZoneFunction get _createTimer => |
| + const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); |
| + @deprecated |
| + _ZoneFunction get _createPeriodicTimer => |
| + const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); |
| + |
| // The parent zone. |
| _Zone get parent => null; |
| @@ -1155,6 +1432,18 @@ class _RootZone extends _Zone { |
| _rootScheduleMicrotask(null, null, this, f); |
| } |
| + Task createTask(TaskSpecification task, TaskCreate create) { |
| + return _rootcreateTask(null, null, this, task, create); |
| + } |
| + |
| + void runTask(Task task, Object arg, TaskRun run) { |
| + _rootRunTask(null, null, this, task, arg, run); |
| + } |
| + |
| + void cancelTask(Task task, TaskCancel cancel) { |
| + _rootCancelTask(null, null, this, task, cancel); |
| + } |
| + |
| Timer createTimer(Duration duration, void f()) { |
| return Timer._createTimer(duration, f); |
| } |