dart-isolates

Dart - Isolate Cross Window Communication

你。 提交于 2019-12-11 02:32:28
问题 Is cross-window communication possible with Dart isolates? Here is my scenario: User opens web site in browser window A and window A spawns a new isolate. The user then clicks a link that creates a new tab and opens browser window B (assume the link is in the same domain, etc...). Can browser window B send and receive messages from the isolate spawned by browser window A, and if so, how? 回答1: Cross window communication is not possible using isolates messaging alone. However you can do cross

Shared memory between Isolates using IndexedDB

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:44:01
问题 I'm working with Isolates right now and wanted to know if using IndexedDB to share data between Isolates is a good way to communicate? Specifically, I want one Isolate to be able to write to it, then tell the other Isolates they may readonly it. This is data that would be considered unchanging once it is written and is fairly large. The main reason I want to do this is because I don't want to send a 6MB Map to 3 different Isolates since it is a bit intensive on the program. 回答1: Web workers

Dart: handle incoming HTTP requests in parallel

牧云@^-^@ 提交于 2019-12-09 14:25:50
问题 I am trying to write an HTTP server in Dart that can handle multiple requests in parallel. I have been unsuccessful at achieving the "parallel" part thus far. Here is what I tried at first: import 'dart:io'; main() { HttpServer.bind(InternetAddress.ANY_IP_V4, 8080).then((HttpServer server) { server.listen((HttpRequest request) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); while (stopwatch.elapsedMilliseconds < 1000) { /* do nothing */ } request.response.statusCode = HttpStatus

Dart Isolates As Workers

≡放荡痞女 提交于 2019-12-09 06:50:52
问题 Edited to make the question more clear. I am trying to work with Isolates (or Web Workers) in Dart. The only ways I can find to communicate between the main and isolate threads are send and call & then from the main thread. But that's a nice way for the main thread to pass some data to the isolate. What's if I want the isolate to be the one who generates information? Like a game engine that does all the physics in a worker and then sends an updated world information to the main thread? In

What is the best way to track the state of an Isolate in Dart?

痞子三分冷 提交于 2019-12-07 21:06:23
问题 I'm trying to track whether the isolate is currently running or not (and in the future whether it has errored out) using isolate.addOnExitListener(...). However, the following snippet of code is not working how I would expect: items.forEach((name, item) async { Isolate isolate = await Isolate.spawnUri(...); item.status = "running"; ReceivePort receivePort = new ReceivePort(); isolate.addOnExitListener(receivePort.sendPort); receivePort.listen((message){ if (message == null) { print("Item

Dart / Flutter: async behaviour of an Isolate's top level function

橙三吉。 提交于 2019-12-07 17:53:56
问题 Aye Aye good people, I'm experiencing a weird behavior when using the top level function of an isolate asynchronously; you can find example code HERE, but in short as top level function of an isolate this works: String _syncHandle(int data) { return 'done'; } and this doesn't: Future<String> _syncHandle(int data) async { return 'done'; } can anybody explain me why? (or if should work, why isn't doing so in my code?) thank you in advance Francesco ... [edit: just noticed that a similar

What is the best way to track the state of an Isolate in Dart?

本小妞迷上赌 提交于 2019-12-06 12:25:08
I'm trying to track whether the isolate is currently running or not (and in the future whether it has errored out) using isolate.addOnExitListener(...). However, the following snippet of code is not working how I would expect: items.forEach((name, item) async { Isolate isolate = await Isolate.spawnUri(...); item.status = "running"; ReceivePort receivePort = new ReceivePort(); isolate.addOnExitListener(receivePort.sendPort); receivePort.listen((message){ if (message == null) { print("Item exited: ${item.name}"); item.status = "stopped"; } }); }); The "items" map contains 3 values, each with a

Recent documentation about Dart Isolates

橙三吉。 提交于 2019-12-05 08:29:19
I recently started with Dart ( www.dartlang.org ) and really like it so far. A very promising feature are isolates, but I am not sure on how to start. The documentation I found so far is from before a breaking change ( BREAKING CHANGE: dart:isolate ) in October 2013. The information in this "Breaking change" email is quite complicated and it looks like the new api is more complicated than the old. I've got some questions: Is the dart:isolate api stable? Is there any up-to-date documentation? Are there any working examples? Thanks for any help, Hendrik Jan I tried this example and it works

Dart: handle incoming HTTP requests in parallel

筅森魡賤 提交于 2019-12-04 01:35:21
I am trying to write an HTTP server in Dart that can handle multiple requests in parallel. I have been unsuccessful at achieving the "parallel" part thus far. Here is what I tried at first: import 'dart:io'; main() { HttpServer.bind(InternetAddress.ANY_IP_V4, 8080).then((HttpServer server) { server.listen((HttpRequest request) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); while (stopwatch.elapsedMilliseconds < 1000) { /* do nothing */ } request.response.statusCode = HttpStatus.OK; request.response.write(stopwatch.elapsedMilliseconds.toString()); request.response.close()

Dart Isolates As Workers

帅比萌擦擦* 提交于 2019-12-03 07:43:35
Edited to make the question more clear. I am trying to work with Isolates (or Web Workers) in Dart. The only ways I can find to communicate between the main and isolate threads are send and call & then from the main thread. But that's a nice way for the main thread to pass some data to the isolate. What's if I want the isolate to be the one who generates information? Like a game engine that does all the physics in a worker and then sends an updated world information to the main thread? In JavaScript you can send data at any time. Is there an efficient way in Dart? Or do I still have to wait