future

Scala transforming a Seq with Future

怎甘沉沦 提交于 2019-12-06 11:12:07
I have a Seq of a tuple that looks like this: Seq[(Future[Iterable[Type1]], Future[Iterator[Type2]])] I want to transform this into the following: Future[Seq([Iterable[Type1], [Iterable[Type2])] Is this even possible? This should do the trick val a: Seq[(Future[Iterable[Type1]], Future[Iterable[Type2]])] = ... val b: Future[Seq[(Iterable[Type1], Iterable[Type2])]] = Future.sequence(a.map{ case (l, r) => l.flatMap(vl => r.map(vr => (vl, vr))) }) A bit simpler than Till Rohrmann's answer. Not tested, but should work. val seq: Seq[(Future[Iterable[Type1]], Future[Iterable[Type2]])] = ... val seq2

Akka: What happens when you tell an ActorRef and it expects you to ask?

孤者浪人 提交于 2019-12-06 09:49:07
I have the following: val future = myActor ? Message And in my actor my receive message has something like this: sender ! Response If I do the following and ignore the response, is there any negative impact? myActor ! Message Maybe I'm just missing where it says this in the documentation. Is it like a method that returns a value and the caller doesn't assign the return value to anything? If I make that call from another actor is there going to be some weird threading issue or memory leaks that result from it? My unit tests don't seem to be affected but it's kind of a contrived. I'm hoping I'm

What gives a std::future some shared state

人走茶凉 提交于 2019-12-06 09:12:31
A std::future has a std::future::valid method, which indicates whether the future object refers to some shared state . None of the constructors construct a future object that refers to shared state (except the move constructor, which can move the shared state from one future object to another). All the methods of the class ( get , wait , wait_for and wait_until require the future object to have shared state as a precondition (they have undefined behaviour if valid() == false ). How then can a std::future acquire some shared state and become useful? You do not normally use a std::future in

Android volley get callback when all requests finish

扶醉桌前 提交于 2019-12-06 06:35:06
问题 I am using volley to queue a series of requests. I am showing a progress dialog to the user when these requests are happening. Is there a way I can check when all these requests are finished. This is what I want. //Show progress bar for(int i=0;i<size;i++) { //create request and add the request requestQueue.add(request); } // When last request finsihes dismiss progres bar Is there a solution to this problem. 回答1: You can keep the total number of requests in a member variable : int

A better syntax for recovery from a for comprehension

独自空忆成欢 提交于 2019-12-06 06:13:47
问题 I have a number of functions that return a future that is the result of a for comprehension, but i need to need to recover from some possible failures on the way out. The standard syntax seems to capture the for comprehension as an intermediate results like so: def fooBar(): Future[String] = { val x = for { x <- foo() y <- bar(x) } yield y x.recover { case SomeException() => "bah" } } The best alternative to I've found is to wrap the whole for comprehension in parentheses: def fooBar():

How can I get a future from boost::asio::post?

房东的猫 提交于 2019-12-06 05:18:33
问题 I am using Boost 1.66.0, in which asio has built-in support for interoperating with futures (and for some time now). The examples I've seen online indicate how to achieve this cleanly when using networking functions such as async_read , async_read_some , etc. That is done by providing boost::asio::use_future in place of the completion handler, which causes the initiating function to return a future as expected. What kind of object do I need to provide or wrap my function in to get the same

Sequencing `Future`s with timeout

本秂侑毒 提交于 2019-12-06 05:12:04
问题 I utilized the TimeoutScheduler introduced at Scala Futures - built in timeout?. However, now my program does not terminate as before without TimeoutScheduler . I have two Future s: res1 and res2 . Both with a timeout of 15 seconds. In the end I sequence both Future s in order to shutdown the HTTP executor properly in the onComplete callback. Without using withTimeout the program terminates right after http.shutdown . But with using withTimeout is doesn't. Why? There must be some further

Java Concurrency: Is cancelling Futures necessary for them to be Garbage Collected?

有些话、适合烂在心里 提交于 2019-12-06 02:10:43
I am writing some code where I might need to create an unbounded number of future objects (java.util.concurrent.Future). But I am worried about running out of memory at some point. Couple of questions here: Does the jvm know that once the future has completed, it is not being refernced anywhere and therefore is eligible for GC (even if the thread within which it was created is still alive and running)? Ideally, I wouldn't want to keep track of these futures themselves. But if I do keep the reference of these futures and periodically call cancel on them, will that make them available for GC?

NHibernate Future Object Graph Many Queries

我与影子孤独终老i 提交于 2019-12-05 23:21:25
问题 Given a multi level object graph being called using Future as: var Dads = db.Session.Query<Parent>().Where(P => P.EntityKey == Id) .ToFuture<Parent>(); var Kids = db.Session.Query<Kid>().Where(K => K.Parent.EntityKey == Id) .ToFuture<Kid>(); when I call var Dad = dads.ToList() I see the batch go across the wire and show in profiler. Problem is when enumerating the collection it is still sending one off queries to the db Eg. for each (Kid kid in Dad.Kids) // This seems to hit the database {

React for futures

送分小仙女□ 提交于 2019-12-05 22:28:13
问题 I am trying to use a divide-and-conquer (aka fork/join) approach for a number crunching problem. Here is the code: import scala.actors.Futures.future private def compute( input: Input ):Result = { if( pairs.size < SIZE_LIMIT ) { computeSequential() } else { val (input1,input2) = input.split val f1 = future( compute(input1) ) val f2 = future( compute(input2) ) val result1 = f1() val result2 = f2() merge(result1,result2) } } It runs (with a nice speed-up) but the the future apply method seems