future

How do Clojure futures and promises differ?

北慕城南 提交于 2019-11-28 14:49:26
问题 Both futures and promises block until they have calculated their values, so what is the difference between them? 回答1: Answering in Clojure terms, here are some examples from Sean Devlin's screencast: (def a-promise (promise)) (deliver a-promise :fred) (def f (future (some-sexp))) (deref f) Note that in the promise you are explicitly delivering a value that you select in a later computation ( :fred in this case). The future, on the other hand, is being consumed in the same place that it was

Why is this not compiling? (RValue as thread CTOR arguments)

只谈情不闲聊 提交于 2019-11-28 11:11:40
问题 Hello here is a test code I wrote on MSVC12. Could someone tell me why the std::move when I pass parameters to the thread are not converting the variabes to RValue refs?? And what I should do. Thank you! ///some arbitrary long task std::string DumpFile(std::string path){ std::this_thread::sleep_for(std::chrono::seconds(10)); return path; } void run_promise(std::promise<std::string> &&_prom, std::string &&_path){ try { std::string val = DumpFile(std::move(_path)); _prom.set_value(val); } catch

How to guarantee sequentiality for forks in akka

给你一囗甜甜゛ 提交于 2019-11-28 08:47:01
问题 We're creating a chain of actors for every (small) incoming group of messages to guarantee their sequential processing and piping (groups are differentiating by common id). The problem is that our chain has forks, like A1 -> (A2 -> A3 | A4 -> A5) and we should guarantee no races between messages going through A2 -> A3 and A4 -> A5 . The currrent legacy solution is to block A1 actor til current message is fully processed (in one of sub-chains): def receive { //pseudocode case x => ... val f =

How to return a future combinator with `&self`

喜欢而已 提交于 2019-11-28 08:35:16
问题 I have this piece of code: impl ArcService for (Box<MiddleWare<Request>>, Box<ArcService>) { fn call(&self, req: Request, res: Response) -> Box<Future<Item = Response, Error = Error>> { box self.0.call(req).and_then(move |req| self.1.call(req, res)) } } pub trait ArcService: Send + Sync { fn call(&self, req: Request, res: Response) -> Box<Future<Item = Response, Error = Error>>; } pub trait MiddleWare<T>: Sync + Send { fn call<'a>(&'a self, param: T) -> Box<Future<Item = T, Error = Error> +

Unknown exception from std::promise

狂风中的少年 提交于 2019-11-28 07:52:33
问题 What is wrong with the following code? When ran the program aborts with an unknown exception #include <iostream> #include <future> int main() { auto promise = std::promise<int>{}; auto future_one = promise.get_future(); promise.set_value(1); return 0; } The error output is terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1 Aborted (core dumped) g++ --version for me gives g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609 Copyright (C) 2015 Free

AngularJS promises not firing when returned from a service [duplicate]

半腔热情 提交于 2019-11-28 07:03:07
Possible Duplicate: angularjs - promise never resolved in controller I'm wrapping a slow WebSockets server in a AngularJS service, and then calling into that service from my controllers. If I chain callbacks onto callbacks onto callbacks, everything works just fine, any the UI updates asynchronously. When I try to use $q.defer() to clean up that mess of callbacks, it seems my deferred never gets called. I'm familiar with the concepts of deferred from Python's Twisted, so I think conceptually everything should work - but it doesn't. This is the shortest example I could come up with, the slow

How to send data through a futures Stream by writing through the io::Write trait?

筅森魡賤 提交于 2019-11-28 06:25:26
问题 I have a function that takes a &mut io::Write and I'd like to use it to send a streaming response from the actix-web server without having to buffer the whole response. The function is "pushing" the data, and I can't change the function (that's the whole premise of this question) to use async streams or other kind of polling. Currently I'm forced to use &mut Vec (which implements io::Write ) to buffer the whole result and then send the Vec as the response body. However, the response may be

How to carry on executing Future sequence despite failure?

天涯浪子 提交于 2019-11-28 05:54:06
The traverse method from Future object stops at first failure. I want a tolerant/forgiving version of this method which on occurrence of errors carries on with the rest of the sequence. Currently we have added the following method to our utils: def traverseFilteringErrors[A, B <: AnyRef] (seq: Seq[A]) (f: A => Future[B]): Future[Seq[B]] = { val sentinelValue = null.asInstanceOf[B] val allResults = Future.traverse(seq) { x => f(x) recover { case _ => sentinelValue } } val successfulResults = allResults map { result => result.filterNot(_ == sentinelValue) } successfulResults } Is there a better

Python: Wait on all of `concurrent.futures.ThreadPoolExecutor`'s futures

北城余情 提交于 2019-11-28 05:47:08
I've given concurrent.futures.ThreadPoolExecutor a bunch of tasks, and I want to wait until they're all completed before proceeding with the flow. How can I do that, without having to save all the futures and call wait on them? (I want an action on the executor.) Bakuriu Just call Executor.shutdown : shutdown(wait=True) Signal the executor that it should free any resources that it is using when the currently pending futures are done executing . Calls to Executor.submit() and Executor.map() made after shutdown will raise RuntimeError . If wait is True then this method will not return until all

How do I iterate over a Vec of functions returning Futures in Rust?

给你一囗甜甜゛ 提交于 2019-11-28 05:13:32
问题 Is it possible to loop over a Vec , calling a method that returns a Future on each, and build a chain of Future s, to be evaluated (eventually) by the consumer? Whether to execute the later Future s would depend on the outcome of the earlier Future s in the Vec . To clarify: I'm working on an application that can fetch data from an arbitrary set of upstream sources. Requesting data would check with each of the sources, in turn. If the first source had an error ( Err ), or did not have the