future

Sequentially combine arbitrary number of futures in Scala

流过昼夜 提交于 2019-12-06 20:43:19
问题 I'm new to scala and I try to combine several Futures in scala 2.10RC3. The Futures should be executed in sequential order. In the document Scala SIP14 the method andThen is defined in order to execute Futures in sequential order. I used this method to combine several Futures (see example below). My expectation was that it prints 6 but actually the result is 0 . What am I doing wrong here? I have two questions: First, why is the result 0 . Second, how can I combine several Futures , so that

Exception propagation and std::future

萝らか妹 提交于 2019-12-06 19:16:02
问题 My understanding is that when an asynchronous operation throws an exception, it will be propagated back to a thread that calls std::future::get() . However, when such a thread calls std::future::wait() , the exception is not immediately propagated - it'll be thrown upon a subsequent call to std::future::get() . However, In such a scenario, what is supposed to happen to such an exception if the future object goes out of scope after a call to std::future::wait() , but prior to a call to std:

Wait for an unknown number of futures

拥有回忆 提交于 2019-12-06 19:13:58
问题 In Scala 2.10, what is a correct way to write a function that returns a future which completes when all futures in a list complete? After researching and experimenting, I have developed the code below, in a Scala Worksheet: import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration._ import scala.concurrent._ object ws2 { def executeFutures(futures: Seq[Future[Unit]]): Future[Unit] = { def cascadeFutures(futureSeq: Seq[Future[Unit

Flutter can't read from Clipboard

自作多情 提交于 2019-12-06 16:46:18
问题 I come asking for quite a specific question regarding Flutter and the Future and await mechanism, which seems to be working, but my Clipboard does not really function while operating with my editable text fields, even following Google's advice on implementation... This is my code for pasting: onPressed: () async { await getMyData('text'); _encodingController.text = clipData; Scaffold.of(context).showSnackBar( new SnackBar( content: new Text( "Pasted from Clipboard"), ), ); }, what doesnt work

Scala: completing a Future when other Futures are completed

我是研究僧i 提交于 2019-12-06 15:34:13
I have references to n Future instances f1,.....fn . Is it possible to use Future.apply to create a Future that would complete only when at least one of the n Futures completes, without constantly checking their completion status, but instead by some more efficient way, maybe a callback? Future.firstCompletedOf(Seq(f1, ..., fn)) Asynchronously and non-blockingly returns a new Future to the result of the first future in the list that is completed. 来源: https://stackoverflow.com/questions/47068342/scala-completing-a-future-when-other-futures-are-completed

py 并发之Future

守給你的承諾、 提交于 2019-12-06 14:10:23
目录 例 几个问题 链concurrent.futures 例 # -*- encoding -*- ''' py 3.6 sulime ''' import concurrent.futures import requests import time now = lambda: time.perf_counter() def download_one(url): try: req = requests.get(url) req.raise_for_status() # print(req.status_code) req.encoding = req.apparent_encoding print('Read {} from {}'.format(len(req.text), url)) except: print(404) def download_all(sites): # with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor: # 并发 # with concurrent.futures.ProcessPoolExecutor() as executor: # 并行 # executor.map(download_one, sites) with concurrent.futures

An Akka/Scala promise that requires two actors to complete

一个人想着一个人 提交于 2019-12-06 13:20:34
I am building a stock market application using Scala and Akka. The market matches buyers and sellers and then sends a Promise[Transaction] to both the buyer and the seller that needs to be completed (at some point) in order for the transaction to be processed. Issue is that the promise could complete with failure because either buyer has insufficient funds, seller has insufficient shares. How can I create a Scala promise that requires the coordination of two actors to complete? You are right not to want to use ask -- that should be avoided when possible. Here is how you can send Promises to

Flutter.wait() for multiple futures

帅比萌擦擦* 提交于 2019-12-06 12:18:48
问题 I'm trying to catch the error when my device has no internet connection. I've built out 2 future methods, 1 to import a json and 1 to look into the database. I have a future builder that's suppose to wait for both futures to finish before building out the grid view but it seems like the offlineFlashCardList is being prematurely called due to the connection error. Any idea how to make it wait for both futures to finish before the snapshot error gets called? import 'package:flutter/material

Queryover dynamic fetch with joins

半世苍凉 提交于 2019-12-06 12:07:01
iam trying a new query with nhibernate and find a new problem :( take this as model: public class D { int id; } public class C { int id; } public class B { int id; ICollection<C> Cs; ICollection<D> Ds; } public class A { int id; ICollection<B> Bs; } i want A object that have a particular B object and dinamically eager fetch Cs or Ds collection of selected B: public virtual A Read(int idB, params Expression<Func<Attivita, object>>[] eagerFields) i start with IEnumerable<A> query = _session.QueryOver<A>() .JoinQueryOver(a => a.Bs) .Where(b => b.Id == idB) .Future<A>(); foreach (Expression<Func<A

Sequential composition for arbitrary number of calls in Vertx with Futures

亡梦爱人 提交于 2019-12-06 11:52:01
We use Futures in vertx in examples like: Future<JsonObject> fetchVehicle = getUserBookedVehicle(routingContext, client); fetchVehicle.compose(vehicleJson -> vehicleDoor(routingContext, client, vehicleJson, lock)).setHandler( asyncResult -> { if (asyncResult.succeeded()) { LOG.info("Door operation succeeded with result {}", asyncResult.result().encode()); handler.handle(Future.succeededFuture(new AsyncReply(200, "OK"))); } else { handler.handle(Future.failedFuture(asyncResult.cause())); } }); where we handle 2 calls for example. OR I have another snippet where I can handle any number of