问题
I found this very strange and unfortunate behavior in Dart. When I import 'dart:html' in my main file, my Isolate stops working.
With my file "isolate.dart" :
main(){
print('BAM');
}
This prints "BAM":
import 'dart:core';
import 'dart:isolate';
void main() {
Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);
}
but this prints nothing :
import 'dart:core';
import 'dart:isolate';
import 'dart:html';
void main() {
Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);
}
How can I get Isolate to work while using the html import?
UPDATE : I've found this code https://github.com/TomCaserta/ExampleIsolate and tried to work it to find the problem. It seems like the print() call from the Isolate is causing problems.
回答1:
This are known bugs/limitations. It is being worked on.
Currently it is not possible to access functionality of the 'dart:html' package in an isolate and 'print()' crashes the isolate probably because there is no package with a 'print' functionality available where the command can be redirected to.
The Dart issue tracker seems not to be available currently.
I try again later to add some references.
Some open issues that I think are related:
- Print statement inside isolate crashes isolate.
- Isolate.spawn not allowed in Dartium DOM isolate
- Support spawn of dom isolates in Dartium
- Unable to break on breakpoint in library loaded by spawnUri
- isolate in dartium not creating httprequest, works when compiled to javascript
来源:https://stackoverflow.com/questions/23419979/dart-isolate-not-working-when-using-html-import