Is there a way to pause an isolate at all?

113 views
Skip to first unread message

Charles Xie

unread,
Apr 3, 2014, 8:56:58 AM4/3/14
to mi...@dartlang.org
I know the API says that the pause and resume methods of Isolate haven't been implemented yet. But is there a workaround?

I have a situation in which I will need to run some compute-intensive tasks (such as solving the Navier-Stokes equation) in the background and then update the results on a HTML canvas periodically. I will need the ability to pause and resume the computation at any time. If Isolate is not the way to go in Dart now, what options do we have?

Thanks in advance.

Peter Ahé

unread,
Apr 3, 2014, 9:22:26 AM4/3/14
to General Dart Discussion
Perhaps you can write your computation so that it is composed of tasks
that each only run for a few milliseconds.

Then you can do the following:

import 'dart:async';

processTasks() {
Stopwatch sw = new Stopwatch()..start();
do {
processTask();
} while (sw.elapsedMilliseconds < 15);
Timer.run(processTasks);
}

This should allow the isolate to process incoming messages within 15
milliseconds.

With this setup you can send a message to the isolate to tell it to
pause or resume.

Cheers,
Peter
> --
> For other discussions, see https://groups.google.com/a/dartlang.org/
>
> For HOWTO questions, visit http://stackoverflow.com/tags/dart
>
> To file a bug report or feature request, go to http://www.dartbug.com/new
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to misc+uns...@dartlang.org.

Brendan Duncan

unread,
Apr 22, 2014, 6:26:17 PM4/22/14
to mi...@dartlang.org
I have been trying to figure out a solution to this as well. I have a heavy processing isolate that I want to be able to communicate with, but it's too busy to hear any messages I send to it.

I tried using a Timer based approach like Peter suggested, for adding a delay to the outer computation loop to give the event queue a chance to be processed, but Timers are not supported by background Isolates:

    Exception: UnimplementedError: Timers on background isolates are not supported in the browser

Any other ideas?

Peter Ahé

unread,
Apr 23, 2014, 4:52:52 AM4/23/14
to General Dart Discussion
On Wed, Apr 23, 2014 at 12:26 AM, Brendan Duncan
<brenda...@gmail.com> wrote:
> I have been trying to figure out a solution to this as well. I have a heavy
> processing isolate that I want to be able to communicate with, but it's too
> busy to hear any messages I send to it.
>
> I tried using a Timer based approach like Peter suggested, for adding a
> delay to the outer computation loop to give the event queue a chance to be
> processed, but Timers are not supported by background Isolates:

I don't think delaying will help. What you have to ensure is that you
don't schedule too much.

> Exception: UnimplementedError: Timers on background isolates are not
> supported in the browser

That sounds like a bug, you can report it here: http://dartbug.com/new.

Cheers,
Peter

Günter Zöchbauer

unread,
Apr 23, 2014, 6:18:47 AM4/23/14
to mi...@dartlang.org
Reply all
Reply to author
Forward
0 new messages