You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an error is thrown in an async block, it propagates to the zone's error handler much more slowly than one thrown in a non-async context. For example:
This is very important for testing (among other things), where errors have to be handled specially and users have strong expectations for their consistent ordering.
The text was updated successfully, but these errors were encountered:
This might be trivial to fix, by switching to sync-completers.
I'm too tired to think too deeply about it, and it will need more people thinking this through, but at the moment I think that should do it.
For dart2js the patch would be (assuming that the completer-constructor lookup is only used for the async-rewrite):
diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart
index 986a313..f3067d1 100644
If an error is thrown in an async block, it propagates to the zone's error handler much more slowly than one thrown in a non-async context. For example:
import 'dart:async';
void main() {
runZoned(() async {
scheduleMicrotask(() => throw 'in microtask');
throw 'in async function';
}, onError: (error, stackTrace) {
print("caught $error");
});
}
this prints:
in microtask
in async function
which is not expected, since "in async function" is thrown before "in microtask". Compare to the version without async:
import 'dart:async';
void main() {
runZoned(() {
scheduleMicrotask(() => throw 'in microtask');
throw 'in async function';
}, onError: (error, stackTrace) {
print("caught $error");
});
}
and the version that runs the entire body in a microtask:
import 'dart:async';
void main() {
runZoned(() {
scheduleMicrotask(() {
scheduleMicrotask(() => throw 'in microtask');
throw 'in async function';
});
}, onError: (error, stackTrace) {
print("caught $error");
});
}
both of which print
in async function
in microtask
as expected.
This is very important for testing (among other things), where errors have to be handled specially and users have strong expectations for their consistent ordering.
The text was updated successfully, but these errors were encountered: