0

I am having some difficulties making use of isolates in Dart. The first problem is I wanted to use dart:js to use a javascript library in one of my isolates. I tried with the following code:

void runCode(SendPort sendPort)
{
    print("still ok...");
    JsObject object = new JsObject(context['jsCode']);
    print("still ok?");
}

void main()
{
    ReceivePort receivePort = new ReceivePort();
    JsObject object = new JsObject(context['jsCode']);
    print("ok so far");
    Isolate.spawn(runCode, receivePort.sendPort);
}

The code runs as far as "still ok..." in the runCode function and breaks when I try to use JsObject.

The second problem was I wanted to use the fileSystem API in the isolate. So I tried the following:

void runCode(SendPort sendPort)
{
    window.requestFileSystem.then((FileSystem filesytem) => print('ok'));
}

void main()
{
    ReceivePort receivePort = new ReceivePort();
    Isolate.spawn(runCode, receivePort.sendPort);
}

This second example breaks when I reach the filesystem.

I have read: Dart : Isolate not working when using html import and from here it suggests that dart:html cannot be used in an isolate. Is this the reason why the filesystem API will not work? Is this the same case for dart:js? Or am I completely missing something?

Thanks for any help!

1
  • AFAIK this will be fixed with DDC (Dart development compiler) when there is no dependency on Dartium for development anymore which makes such scenarios complicated. Commented Mar 22, 2017 at 14:57

1 Answer 1

1

I've read somewhere that only the main thread has access to the DOM, which would cause any other JS action to fail if not in the main thread.

1
  • Thanks - checked this and that was exactly it.
    – SSS
    Commented Mar 26, 2017 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.