future

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

Behaviours of scala's Future.sequence method

不羁的心 提交于 2019-12-07 16:21:51
问题 I wrote this method: import scala.concurrent._ import ExecutionContext.Implicits.global import scala.util.{ Success, Failure } object FuturesSequence extends App { val f1 = future { 1 } val f2 = future { 2 } val lf = List(f1, f2) val seq = Future.sequence(lf) seq.onSuccess { case l => println(l) } } I was expecting Future.sequence to gather a List[Future] into a Future[List] and then wait for every futures (f1 and f2 in my case) to complete before calling onSuccess on the Future[List] seq in

Bluebird Promise Cancellation

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 13:11:46
问题 Say I have the following Promise chain: var parentPromise = Promise.resolve() .then(function () { var condition = false; if (condition) { return parentPromise.cancel('valid reason'); } else { return Promise.resolve() .then(function () { var someOtherCondition = true; if (someOtherCondition) { console.log('inner cancellation'); return parentPromise.cancel('invalid reason'); } }); } }) .catch(Promise.CancellationError, function (err) { console.log('throwing'); if (err.message !== 'valid reason'

Future Recursion Patterns/Future Chaining of arbitrary length

不问归期 提交于 2019-12-07 11:02:25
问题 I'm curious about the best way to recursively build a chain of Akka futures which will run sequentially, if a doWork call in a future fails, the future should be retried up to 3 times, the chain should fail if it runs out of retry attempts. Assuming all doWork calls pass the returned future futChain should only complete. object Main extends App { val futChain = recurse(2) def recurse(param: Int, retries: Int = 3): Future[String] { Future { doWorkThatMayFailReturningString(param...) }

How to select between a future and stream in Rust?

空扰寡人 提交于 2019-12-07 07:49:20
问题 I've just started experimenting with futures/tokio in Rust. I can do really basic things with just futures or just with streams. I was wondering how you can select between future and a stream. How can I extend the toy problem from the tokio documentation to use tokio_timer::Timer to do a timed HTTPS request? extern crate futures; extern crate native_tls; extern crate tokio_core; extern crate tokio_io; extern crate tokio_tls; use std::io; use std::net::ToSocketAddrs; use futures::Future; use

Exception during Callable execution

…衆ロ難τιáo~ 提交于 2019-12-07 04:48:17
问题 I have the following Callable: public class Worker implements Callable<Boolean>{ @Override public Boolean call(){ boolean success=true; //do Something return success; } } Now I'm executing it: Worker worker - new Worker(); Future<Boolean> submit = executor.submit(worker); I'm storing the submit in kind of hashMap for some operation to be performed somewhere in code. How can I know if any exception has occured in worker.call() function? Will submit.isCancelled() return true if some sort of

Why does this list-of-futures to future-of-list transformation compile and work?

旧时模样 提交于 2019-12-07 03:29:13
问题 Disclaimer: the code snippet below relates to one of ongoing Coursera courses. Let's consider it's posted just for a learning purpose and should not be used for submitting as a solution for one's homework assignment. As the comment below states, we need to transform a list of Futures to a single Future of a list. More than that, the resulting Future should fail if at least one of input futures failed. I met the following implementation and I don't understand it completely. /** Given a list of

How to convert std::future<T> to std::future<void>?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 02:20:10
问题 I have a situation where I have a std::future<some_type> resulting from a call to API A, but need to supply API B with a std::future<void> : std::future<some_type> api_a(); void api_b(std::future<void>& depend_on_this_event); In the absence of proposed functionality such as .then() or when_all() , is there any efficient way to throw away the value attached to a std::future<T> and be left only with the underlying std::future<void> representing the event's completion? Something like the

Execution context for futures in Actors

China☆狼群 提交于 2019-12-07 01:46:42
问题 I have a Actor, and on some message I'm running some method which returns Future. def receive: Receive = { case SimpleMessge() => val futData:Future[Int] = ... futData.map { data => ... } } Is it possible to pass actual context to wait for this data? Or Await is the best I can do if I need this data in SimpleMessage ? 回答1: If you really need to wait for the future to complete before processing the next message, you can try something like this: object SimpleMessageHandler{ case class

How to best handle Future.filter predicate is not satisfied type errors

故事扮演 提交于 2019-12-07 01:24:56
问题 I love how scala is type safe, but one runtime error I keep running into is Future.filter predicate is not satisfied I can see why I am getting this error, just looking for advice on how to best work around this error and handle it gracefully or maybe I am doing this wrong? val r: Future[play.api.mvc.Result] = for { account <- accountServer.get(...) if account.isConfirmed orders <- orderService.get(account, ...) } yield { ... } If the account is not confirmed, I will get the above error. I