I investigated the isolate to see if it can support waiting another isolate to finish, then continue the rest of job.
But Dart's concurrency is really restrictive, there seems no way to achieve this.
Considering many poor design of asynchronity of current Dart, server side Dart seems not good option right now.
Maybe I may try 'Go' as well..
Rob pike and Thompson who are behind Go had been working on this area.
http://doc.cat-v.org/plan_9/4th_edition/papers/sleep
Of cause Java is still OK..
If we define some mapping tool from Dart annotation to JPA annotation, it is still not so bad option.But even we use java in server side, lazy evaluation on Dart client is still not possible. As long as the expected job in client side is low, this may not be a big problem though..
Showing posts with label async. Show all posts
Showing posts with label async. Show all posts
Thursday, November 7, 2013
Monday, November 4, 2013
Dart's Future evaluation order
Dart's future evaluation order is not so clear from source code, so I tested using sample code.
Also this test when stream evaluation happen. listen method also started after the end of main code line and after running all futures. this means listen may create future, but not at the time listen is invoked.
The output will be just <1>.
And the order of future evaluation is the order it was created.
Also this test when stream evaluation happen. listen method also started after the end of main code line and after running all futures. this means listen may create future, but not at the time listen is invoked.
import "dart:async"; main() { Stream stream = new Stream.periodic(const Duration(milliseconds: 1), (x) => x); int receivedCount = 0; var subscription; print("<1>"); int a = 0; new Future.value(1).then((v) { print(">> 1 v: ${v}"); new Future.value(10).then((v) { print(">> 10 v: ${v}"); }); }); bool finished = false; subscription = stream.listen((data) { //expect(data, receivedCount); receivedCount++; print("receivedCount: ${receivedCount}"); finished = true; new Future.value(30).then((v) { print(">> 30 v: ${v}"); }); if (receivedCount == 5) subscription.cancel(); }); new Future.value(2).then((v) { print(">> 2 v: ${v}"); new Future.value(20).then((v) { print(">> 20 v: ${v}"); }); }); /* while (!finished) { } */ print("<2>"); }
<1> <2> >> 1 v: 1 >> 2 v: 2 >> 10 v: 10 >> 20 v: 20 receivedCount: 1 receivedCount: 2 >> 30 v: 30 >> 30 v: 30 receivedCount: 3 receivedCount: 4 >> 30 v: 30 >> 30 v: 30 receivedCount: 5 >> 30 v: 30If we add while loop:
import "dart:async"; main() { Stream stream = new Stream.periodic(const Duration(milliseconds: 1), (x) => x); int receivedCount = 0; var subscription; print("<1>"); int a = 0; new Future.value(1).then((v) { print(">> 1 v: ${v}"); new Future.value(10).then((v) { print(">> 10 v: ${v}"); }); }); bool finished = false; subscription = stream.listen((data) { //expect(data, receivedCount); receivedCount++; print("receivedCount: ${receivedCount}"); finished = true; new Future.value(30).then((v) { print(">> 30 v: ${v}"); }); if (receivedCount == 5) subscription.cancel(); }); new Future.value(2).then((v) { print(">> 2 v: ${v}"); new Future.value(20).then((v) { print(">> 20 v: ${v}"); }); }); while (!finished) { } print("<2>"); }
The output will be just <1>.
<1>These things means future evaluation will happen only main code line was ended.
And the order of future evaluation is the order it was created.
Subscribe to:
Posts (Atom)