How to accept an async function as an argument?

async functions are effectively desugared as returning impl Future. Once you know that, it’s a matter of combining existing Rust techniques to accept a function / closure, resulting in a function with two generic types: use std::future::Future; async fn example<F, Fut>(f: F) where F: FnOnce(i32, i32) -> Fut, Fut: Future<Output = bool>, { f(1, 2).await; … Read more

Await a future, receive an either

You could use Await.ready which simply blocks until the Future has either succeeded or failed, then returns a reference back to that Future. From there, you would probably want to get the Future’s value, which is an Option[Try[T]]. Due to the Await.ready call, it should be safe to assume that the value is a Some. … Read more

Scala – ScheduledFuture

Akka has akka.pattern: def after[T](duration: FiniteDuration, using: Scheduler)(value: ⇒ Future[T])(implicit ec: ExecutionContext): Future[T] “Returns a scala.concurrent.Future that will be completed with the success or failure of the provided value after the specified duration.” http://doc.akka.io/api/akka/2.2.1/#akka.pattern.package

Dart: How to return Future

You don’t need to return anything manually, since an async function will only return when the function is actually done, but it depends on how/if you wait for invocations you do in this function. Looking at your examples you are missing the async keyword, which means you need to write the following instead: Future<void> deleteAll(List … Read more

Futures – map vs flatmap

If you have a future, let’s say, Future[HttpResponse], and you want to specify what to do with that result when it is ready, such as write the body to a file, you may do something like responseF.map(response => write(response.body). However if write is also an asynchronous method which returns a future, this map call will … Read more