Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 43e00e5

Browse files
gfanzhrkirov
authored andcommitted
feat(zone): adds onCreateTimer overriding interface
Add onCreateTimer overriding interface similar to scheduleMicrotask.
1 parent 3db2752 commit 43e00e5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/core/zone.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ typedef void ZoneOnTurnStart();
1414

1515
typedef void ZoneScheduleMicrotask(fn());
1616

17+
typedef async.Timer ZoneCreateTimer(async.ZoneDelegate delegate,
18+
async.Zone zone, Duration duration, fn());
19+
1720
/**
1821
* Handles a [VmTurnZone] onError event.
1922
*/
@@ -85,6 +88,7 @@ class VmTurnZone {
8588
onTurnDone = _defaultOnTurnDone;
8689
onTurnStart = _defaultOnTurnStart;
8790
onScheduleMicrotask = _defaultOnScheduleMicrotask;
91+
onCreateTimer = _defaultOnCreateTimer;
8892
countPendingAsync = _defaultCountPendingAsync;
8993
}
9094

@@ -134,7 +138,7 @@ class VmTurnZone {
134138
async.Timer _onCreateTimer(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, Duration duration, fn()) {
135139
var s = traceEnter(VmTurnZone_createTimer);
136140
try {
137-
return new _WrappedTimer(this, delegate, zone, duration, fn);
141+
return onCreateTimer(delegate, zone, duration, fn);
138142
} finally {
139143
traceLeave(s);
140144
}
@@ -224,6 +228,15 @@ class VmTurnZone {
224228
ZoneScheduleMicrotask onScheduleMicrotask;
225229
void _defaultOnScheduleMicrotask(fn) => _asyncQueue.add(fn);
226230

231+
/**
232+
* Called any time a timer is created. If you override [onCreateTimer],
233+
* you are expected to return a [Timer] which call the function at some point.
234+
*/
235+
ZoneCreateTimer onCreateTimer;
236+
async.Timer _defaultOnCreateTimer(async.ZoneDelegate delegate,
237+
async.Zone zone, Duration duration, fn())
238+
=> new _WrappedTimer(this, delegate, zone, duration, fn);
239+
227240
LongStackTrace _longStacktrace = null;
228241

229242
LongStackTrace _getLongStacktrace(name) {

0 commit comments

Comments
 (0)