问题描述:

Is this possible? That is to say, I tried it and it didn't work. But in theory it should be possible shouldn't it? I'm only passing messages back and forth, isolated memory space, etc.

import 'dart:io';

import 'dart:isolate';

main(){

final sp = spawnUri('path/to/dart_html_app.dart');

}

throws:

IsolateSpawnException: 'Do not know how to load 'dart:html'

网友答案:

As someone already stated, you can't import dart:html in the VM (at least at this point). Your solution would be to split the app into two libraries, where the one you want to spawn does not use dart:html.

What are you actually trying to do? If you think you could have the browser and VM talk via isolates, that's not going to work. Isolates use a thread pool in the VM and Web Workers on the browser if they are available.

If you just want "load the code from this URI and execute it just like any code in a new isolate", then that's certainly possible -- why not? You just have to refactor your code base so that you don't import dart:html except only when you really need it.

相关阅读:
Top