| Index: sdk/lib/_internal/lib/async_patch.dart
|
| diff --git a/sdk/lib/_internal/lib/async_patch.dart b/sdk/lib/_internal/lib/async_patch.dart
|
| index aa1c34239cdc1f132d884f8474002edde3c3e956..c67b3ff7dbe4f31a9d7cb1a385dee1558323fd53 100644
|
| --- a/sdk/lib/_internal/lib/async_patch.dart
|
| +++ b/sdk/lib/_internal/lib/async_patch.dart
|
| @@ -8,7 +8,13 @@ import 'dart:_js_helper' show
|
| Primitives,
|
| convertDartClosureToJS,
|
| loadDeferredLibrary;
|
| -import 'dart:_isolate_helper' show TimerImpl;
|
| +import 'dart:_isolate_helper' show
|
| + IsolateNatives,
|
| + TimerImpl,
|
| + leaveJsAsync,
|
| + enterJsAsync,
|
| + isWorker,
|
| + globalThis;
|
|
|
| import 'dart:_foreign_helper' show JS;
|
|
|
| @@ -27,7 +33,34 @@ patch Timer _createPeriodicTimer(Duration duration,
|
|
|
| patch class _AsyncRun {
|
| patch static void _scheduleImmediate(void callback()) {
|
| + scheduleImmediateClosure(callback);
|
| + }
|
| +
|
| + // Lazily initialized.
|
| + static final Function scheduleImmediateClosure =
|
| + _initializeScheduleImmediate();
|
| +
|
| + static Function _initializeScheduleImmediate() {
|
| + if (JS('', '#.scheduleImmediate', globalThis) != null) {
|
| + return _scheduleImmediateJsOverride;
|
| + }
|
| // TODO(9002): don't use the Timer to enqueue the immediate callback.
|
| + // Also check for other JS options like mutation observer or runImmediate.
|
| + return _scheduleImmediateWithTimer;
|
| + }
|
| +
|
| + static void _scheduleImmediateJsOverride(void callback()) {
|
| + internalCallback() {
|
| + leaveJsAsync();
|
| + callback();
|
| + };
|
| + enterJsAsync();
|
| + JS('void', '#.scheduleImmediate(#)',
|
| + globalThis,
|
| + convertDartClosureToJS(internalCallback, 0));
|
| + }
|
| +
|
| + static void _scheduleImmediateWithTimer(void callback()) {
|
| _createTimer(Duration.ZERO, callback);
|
| }
|
| }
|
|
|