You need to add a return here return _addTagToPost(conn, tag_values); and Future _addTagToPost(Connection conn, Map values) { print('trying to add tag to attached tags'); return conn.execute( "insert into atatched_tags values(currval('posts_post_id_seq'), @tag)", values) .catchError((err){ print('Execute error in addTagToPost: $err'); }); } to keep the async operations connected. Otherwise the connection is...
You could just set a flag which indicates to the delayed code (run from futures) that the result isn't needed anymore. When the delayed code is called it just returns. library cancel_future; import 'dart:async' show Future, Timer; import 'dart:math' show Random; typedef void TaskFunction(Task task); // Container for a task...
void decode(Uint8List data) { new Future(() => decodeGifAnimation(data)).then(prepeare); } or Future decode(Uint8List data) { return new Future(() => decodeGifAnimation(data)).then(prepeare); } if you want to do some async processing when the method returns to call the method like decode(data).then(xxx); ...
I think this might help you - I got a speed up of about 4-5 times: I will add my complete example here: Future<ServerSocket> future = ServerSocket.bind("127.0.0.1", 1000); future.then((ServerSocket sock) { HttpServer s = new HttpServer.listenOn(sock); s.listen((HttpRequest req) { req.response.statusCode = HttpStatus.OK; req.response.headers.contentType = ContentType.parse("image/png"); var file = new File("someImage.png");...
Async code is just scheduled for later execution and the sync code continues executing without waiting for the async code. The method you pass ot Future.then(...) is executed when the scheduled async code is finished. You find a lot of such questions and examples tagged [:dart-async:] here on StackOverflow. I...
I can't spot anything wrong with this code, except that it does not propagate errors. It should work. If completion.complete is invoked then completion.future must complete, check that completion.complete is indeed invoked (e.g. check if there were any network errors on the console, check Network tab in DevTools to see...
First, I'm assuming you're using this as a client-side script and not server-side. Using HttpRequest.getString will strictly return a Future (async method). If you absolutely must have a synchronous request, you can construct a new HttpRequest object and call the open method passing the named parameter: async: false var req...
Future<int> getMrn() { // <== 3 var testRef = firebaseClient.child('mrn'); return testRef.transaction((curVal) { // <== 2) return curVal == null ? 1 : curVal + 1; }).then((result) { var snapshot = result.snapshot; print( snapshot.val()); return result; // <== 1) }); } 1) The value returned from the last chained then()...
Something like: class LoginResult { bool success = false; String username; } Stream<LoginResult> onLogin() async* { while(...) { yield new LoginResult() ..success = isSuccess ..userName = 'someUser'; } } or StreamController<LoginResult> onLoginController = new StreamController<LoginResult>(); // might not be necessary if you only need one listener at most Stream<LoginResult> _onLogin...
This is a known issue that is fixed in the dev channel and will be released in the 1.9 stable channel. See Breakpoint set inside of async function does not trigger.
You can use the Timer class var timer = new Timer(new Duration(seconds: 1), () => print('done')); timer.cancel(); ...
You shouldn't need a Completer here. Future<Directory> createCopyDirectory(Directory directoryToCreate) { return directoryToCreate.create().then((directory) { String userID = split(userDirectory.path).last; Directory contentToCopy = new Directory(globalPathOfDirectoryToCopy); List<Future> creatingContent = new List<Future>(); return contentToCopy .list(recursive: true, followLinks: false) .forEach((File f) { if (f is File) { File fileToCreate = new File(f.path.replaceFirst('pages', userID));...
You don't need to change the loadConfig function. The changes you applied to main() should do.
I'm pretty sure this does the same as your example: void broadcast(Event e) { new Future(() => _ctrl.add(e)); }); } Instead of synchronously adding to _ctrl it registers a callback on the event queue to do the add. This is executed after the previous sync execution is done, so this...
Use an async function instead. import "dart:async"; String _someData = ""; Future<String> getSomeData() async { if (_someData == "") { _someData = await Api.getSomeData(); } return _someData; } Compiler generates approximately the following code: import "dart:async"; String _someData = ""; Future<String> getSomeData() { var $_awaiter = new Completer<String>(); try {...
dart,google-bigquery,dart-async
Something like Future poll() { return new Future.delayed(new Duration(seconds: 1), () => job.getStatus().getState()).then((e) { if(e.done) { somethingToDoAfterGotState()); } else { return poll(); } }); } (not tested)...
import 'dart:html'; import 'dart:async' show Future, Completer; class MyClass { // Define buttons ButtonElement okButton = new ButtonElement()..text = 'OK'; ButtonElement cancelButton = new ButtonElement()..text = 'Cancel'; // Define a constructor MyClass(){ // Create a dialog, define buttons } } void main() async { var dialogResult = await myFunction(); }...
google-app-engine,dart,dart-async
Add --enable-async to the DART_VM_OPTIONS environment variable. You can set it using the app.yaml file like: env_variables: DART_VM_OPTIONS: '--enable-async' You might need to update to the most recent Dart Docker image (for example google/dart-runtime - updated 4h ago)...
The easiest way is to use the "new" async/await main() async { int total = 0; print("Please input an URL"); var url = stdin.readLineSync(); var list = await getImageUrls('url'); for(int i = 0; i < list.length; i++) { var imageUrl = list[i]; var r = await getImageSize(imageUrl); print("$imageUrl, Size: $r...
static Future<List> find(model, [params]){ Db db = new Db("mongodb://127.0.0.1/dart"); var models = []; return db.open().then((o){ db.collection(model).find(params).forEach((d){ models.add(d); }); return models; }); } and use it like find(model, [p1, p2, p3]).then((m) => ...); ...
1) You don't pass a future into Future.sync() but a closure to be executed immediately. Future z = new Future.sync(() => print('bla')); 2) async is an internal package. You import it using import 'dart:async'; Internal packages don't need to be added to pubspec.yaml dependencies because they are always available. The...
First of all you should clarify why you need this. I don't really get why you want them to be executed sequentially - you should give us some more information on the concept behind it. Please give us some more information on what you want to accomplish! The following code...
The stack_trace package https://pub.dartlang.org/packages/stack_trace puts together the whole stack trace. import 'dart:async'; import 'package:stack_trace/stack_trace.dart'; void main() { Chain.capture(() { scheduleAsync(); // <= pass my code in Chain.capture }, onError: (error, stack) { print(error); print(stack); }); } void scheduleAsync() { new Future.delayed(new Duration(seconds: 1)) .then((_) => runAsync()); } void runAsync() {...