Index: runtime/lib/isolate_patch.dart |
diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart |
index 46e4f4039fb0280e74acec775d4b2dd9a71c2e31..d2755f31f5d46088ed8005a107e3c4d31a1f2f90 100644 |
--- a/runtime/lib/isolate_patch.dart |
+++ b/runtime/lib/isolate_patch.dart |
@@ -57,6 +57,28 @@ class _ReceivePortImpl extends Stream implements ReceivePort { |
StreamController _controller; |
} |
+typedef void ImmediateCallback(); |
+ |
+/// The callback that has been registered through `scheduleImmediate`. |
+ImmediateCallback _pendingImmediateCallback; |
+ |
+/// The closure that should be used as scheduleImmediateClosure, when the VM |
+/// is responsible for the event loop. |
+void _isolateScheduleImmediate(void callback()) { |
+ assert(_pendingImmediateCallback == null); |
+ _pendingImmediateCallback = callback; |
+} |
+ |
+/// Provide closurized access to _isolateScheduleImmediate. |
+/// This makes it easier for embedders to set the scheduleImmediate closure. |
+Function get _isolateScheduleImmediateClosure => _isolateScheduleImmediate; |
Ivan Posva
2013/11/27 22:08:32
There is one too many ways to get at the closure.
floitsch
2013/11/28 19:05:54
Dartium usually uses getters, but I should be able
|
+ |
+/// The embedder can execute this function to get hold of |
+/// [_isolateScheduleImmediate] above. |
+Function _getIsolateScheduleImmediateClosure() { |
+ return _isolateScheduleImmediate; |
+} |
+ |
class _RawReceivePortImpl implements RawReceivePort { |
factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; |
@@ -92,7 +114,15 @@ class _RawReceivePortImpl implements RawReceivePort { |
static void _handleMessage( |
_RawReceivePortImpl port, int replyId, var message) { |
assert(port != null); |
+ // TODO(floitsch): this relies on the fact that any exception aborts the |
+ // VM. Once we have non-fatal global exceptions we need to catch errors |
+ // so that we can run the immediate callbacks. |
port._handler(message); |
+ if (_pendingImmediateCallback != null) { |
+ var callback = _pendingImmediateCallback; |
+ _pendingImmediateCallback = null; |
+ callback(); |
+ } |
} |
// Call into the VM to close the VM maintained mappings. |