future

How can I make A future of future into one future object?

血红的双手。 提交于 2019-11-27 13:46:21
问题 Env: Akka 2.1, scala version 2.10.M6, JDK 1.7,u5 Now is my problem: I have: future1 = Futures.future(new Callable<Future<object>>(){...}); future2 = ? extends Object; Future.sequence(future1, future2).onComplete(...) now in first line, I have a future of Future of object, is there any way to convert it into a Future while not blocking my current thread? Is there any method in akka? As far as I checked, I havn't found any yet... First time to have a post....Sry for bad format and organize... :

Future task of ExecutorService not truly cancelling

寵の児 提交于 2019-11-27 13:44:09
I push my Futures from a ExecutorService into a hash map. Later, I may call cancel on Futures from within the hash map. Although the result is true, I later hit breakpoints within the Callable procedure, as if the Future cancel() had no effect. I think it might be a case of two different references here (even though the reference IDs are listed as the same when breakpointing), but was wondering if some experts could chime in. Here's what the code looks like: ExecutorService taskExecutor = Executors.newCachedThreadPool(); Map <String, Future<Object>> results = new HashMap <String, Future<Object

What is the purpose of async/await in Rust?

大憨熊 提交于 2019-11-27 13:18:58
In a language like C#, giving this code (I am not using the await keyword on purpose): async Task Foo() { var task = LongRunningOperationAsync(); // Some other non-related operation AnotherOperation(); result = task.Result; } In the first line, the long operation is run in another thread, and a Task is returned (that is a future). You can then do another operation that will run in parallel of the first one, and at the end, you can wait for the operation to be finished. I think that it is also the behavior of async / await in Python, JavaScript, etc. On the other hand, in Rust, I read in the

Accessing value returned by scala futures

房东的猫 提交于 2019-11-27 11:46:40
I am a newbie to scala futures and I have a doubt regarding the return value of scala futures. So, generally syntax for a scala future is def downloadPage(url: URL) = Future[List[Int]] { } I want to know how to access the List[Int] from some other method which calls this method. In other words, val result = downloadPage("localhost") then what should be the approach to get List[Int] out of the future ? I have tried using map method but not able to do this successfully.` Alexey Romanov The case of Success(listInt) => I want to return the listInt and I am not able to figure out how to do that.

Get the status of a std::future

霸气de小男生 提交于 2019-11-27 11:38:02
Is it possible to check if a std::future has finished or not? As far as I can tell the only way to do it would be to call wait_for with a zero duration and check if the status is ready or not, but is there a better way? You are correct, and apart from calling wait_until with a time in the past (which is equivalent) there is no better way. You could always write a little wrapper if you want a more convenient syntax: template<typename R> bool is_ready(std::future<R> const& f) { return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready; } N.B. if the function is deferred this will

Unable to use for comprehension to map over List within Future

╄→尐↘猪︶ㄣ 提交于 2019-11-27 11:28:13
问题 I have this issue that I have to work around every time. I can't map over something that is contained within a Future using a for comprehension. Example: import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future val f = Future( List("A", "B", "C") ) for { list <- f e <- list } yield (e -> 1) This gives me the error: error: type mismatch; found : List[(String, Int)] required: scala.concurrent.Future[?] e <- list ^ But if I do this it works fine: f.map( _.map( (_

Confusion about threads launched by std::async with std::launch::async parameter

爱⌒轻易说出口 提交于 2019-11-27 11:09:30
问题 I am a little bit confused about the std::async function. The specification says: asynchronous operation being executed "as if in a new thread of execution" (C++11 §30.6.8/11). Now, what does that supposed to mean? In my understanding, the code std::future<double> fut = std::async(std::launch::async, pow2, num); should launch the function pow2 on a new thread and pass the variable num to the thread by value, then sometime in the future, when the function is done, place the result in fut (as

Disable future dates in jQuery UI Datepicker

戏子无情 提交于 2019-11-27 11:04:52
Is it possible to disable future date from today? Let say today is 23/10/2010, so 24/10/2010 onwards are disabled. Sorry I am very new in jQuery and JavaScript. Cyril Gupta Yes, indeed. The datepicker has the maxdate property that you can set when you initialize it. Here's the codez $("#datepicker").datepicker({ maxDate: new Date, minDate: new Date(2007, 6, 12) }); $(function() { $("#datepicker").datepicker({ maxDate: '0'}); }); JAY Code for Future Date only with disable today's date. var d = new Date(); $("#delivdate").datepicker({ showOn: "button", buttonImage: base_url+"images/cal.png",

Scala - ScheduledFuture

≡放荡痞女 提交于 2019-11-27 11:04:05
问题 I am trying to implement scheduled future in Scala. I would like it to wait specific time and then execute the body. So far I tried the following, simple approach val d = 5.seconds.fromNow val f = future {Await.ready(Promise().future, d.timeLeft); 1} val res = Await.result(f, Duration.Inf) but I am getting the TimeoutExcpetion on the future. Is this even the correct approach or should I simply use the ScheduledExecutor from Java? 回答1: You could change your code to something like this: val d =

How to wait for several Futures

那年仲夏 提交于 2019-11-27 10:25:23
Suppose I have several futures and need to wait until either any of them fails or all of them succeed. For example: Let there are 3 futures: f1 , f2 , f3 . If f1 succeeds and f2 fails I do not wait for f3 (and return failure to the client). If f2 fails while f1 and f3 are still running I do not wait for them (and return failure ) If f1 succeeds and then f2 succeeds I continue waiting for f3 . How would you implement it? You could use a for-comprehension as follows instead: val fut1 = Future{...} val fut2 = Future{...} val fut3 = Future{...} val aggFut = for{ f1Result <- fut1 f2Result <- fut2