| 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 c26f29f9291e8c5926101078eefd5077c82b9295..6313e57f45c6c99078c0bf362544c7b3340a4ade 100644
|
| --- a/sdk/lib/_internal/lib/async_patch.dart
|
| +++ b/sdk/lib/_internal/lib/async_patch.dart
|
| @@ -10,7 +10,8 @@ import 'dart:_isolate_helper' show
|
| TimerImpl,
|
| leaveJsAsync,
|
| enterJsAsync,
|
| - isWorker;
|
| + isWorker,
|
| + globalThis;
|
|
|
| import 'dart:_foreign_helper' show JS;
|
|
|
| @@ -29,7 +30,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);
|
| }
|
| }
|
|
|