future

Akka HTTP: Blocking in a future blocks the server

天大地大妈咪最大 提交于 2019-11-26 23:53:50
问题 I am trying to use Akka HTTP to basic authenticate my request. It so happens that I have an external resource to authenticate through, so I have to make a rest call to this resource. This takes some time, and while it's processing, it seems the rest of my API is blocked, waiting for this call. I have reproduced this with a very simple example: // used dispatcher: implicit val system = ActorSystem() implicit val executor = system.dispatcher implicit val materializer = ActorMaterializer() val

Futures vs. Promises

社会主义新天地 提交于 2019-11-26 23:46:35
问题 I'm confusing myself with difference between a future and a promise. Obviously, they have different methods and stuff, but what is the actual use case? Is it?: when I'm managing some async task, I use future to get the value "in future" when I'm the async task, I use promise as the return type to allow the user get a future from my promise 回答1: Future and Promise are the two separate sides of an asynchronous operation. std::promise is used by the "producer/writer" of the asynchronous

What's the difference between a Future and a Promise?

两盒软妹~` 提交于 2019-11-26 23:45:07
问题 What's the difference between Future and Promise ? They both act like a placeholder for future results, but where is the main difference? 回答1: According to this discussion, Promise has finally been called CompletableFuture for inclusion in Java 8, and its javadoc explains: A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion. An example is also given on the

ToRowCountQuery seems to ignore groupings

梦想与她 提交于 2019-11-26 23:37:27
问题 I'm trying to create a rowcount-query from a regular query, but the resulting SQL seems to lack the GROUP BY resulting in a wrong count. Does anyone know what I'm doing wrong. First the queries: var query = Session.QueryOver<InkoopFactuurListItem>() .Where(i => i.KlantId == Klant.Id) .AndRestrictionOn(i => i.Status).IsIn(statussen) .SelectList(list => list .SelectGroup(h => h.Id).WithAlias(() => dto.Id) .SelectGroup(h => h.Banknummer).WithAlias(() => dto.Banknummer) .SelectGroup(h => h

Asynchronous IO in Scala with futures

谁说胖子不能爱 提交于 2019-11-26 21:15:48
Let's say I'm getting a (potentially big) list of images to download from some URLs. I'm using Scala, so what I would do is : import scala.actors.Futures._ // Retrieve URLs from somewhere val urls: List[String] = ... // Download image (blocking operation) val fimages: List[Future[...]] = urls.map (url => future { download url }) // Do something (display) when complete fimages.foreach (_.foreach (display _)) I'm a bit new to Scala, so this still looks a little like magic to me : Is this the right way to do it? Any alternatives if it is not? If I have 100 images to download, will this create 100

scala.concurrent.Future wrapper for java.util.concurrent.Future

旧城冷巷雨未停 提交于 2019-11-26 21:09:30
问题 I'm using Play Framework 2.1.1 with an external java library that produces a java.util.concurrent.Future result. I'm using the scala future's as opposed to Akka which I think is the right thing to do as of Play 2.1. How can I wrap the java.util.concurrent.Future up into a scala.concurrent.Future while still keeping the code non-blocking? def geConnection() : Connection = { // blocking with get connectionPool.getConnectionAsync().get(30000, TimeUnit.MILLISECONDS) } The above code returns a

Cancellation with Future and Promise in Scala

不问归期 提交于 2019-11-26 20:57:22
问题 This is a followup to my previous question. Suppose I have a task, which executes an interruptible blocking call. I would like to run it as a Future and cancel it with failure method of Promise . I would like the cancel to work as follows: If one cancels the task before it finished I would like the task to finish "immediately", interrupting the blocking call if it has already started and I would like the Future to invoke onFailure . If one cancels the task after the task finished I would like

Spark job with Async HTTP call

冷暖自知 提交于 2019-11-26 20:29:13
问题 I build a RDD from a list of urls, and then try to fetch datas with some async http call. I need all the results before doing other calculs. Ideally, I need to make the http calls on differents nodes for scaling considerations. I did something like this: //init spark val sparkContext = new SparkContext(conf) val datas = Seq[String]("url1", "url2") //create rdd val rdd = sparkContext.parallelize[String](datas) //httpCall return Future[String] val requests = rdd.map((url: String) => httpCall

race-condition in pthread_once()?

送分小仙女□ 提交于 2019-11-26 20:14:31
问题 I have a std::future in one thread which is waiting on a std::promise being set in another thread. EDIT: Updated the question with an exemplar app which will block forever: UPDATE: If I use a pthread_barrier instead, the below code does not block. I have created a test-app which illustrates this: Very basically class foo creates a thread which sets a promise in its run function, and waits in the constructor for that promise to be set. Once set, it increments an atomic count I then create a

Js Deferred/Promise/Future compared to functional languages like Scala

不想你离开。 提交于 2019-11-26 19:52:35
问题 I'm mostly using programming languages like Scala and JavaScript. I'm trying to understand the similarities and differences in how async reactive programming is used in both languages. Can you help me? I'm not taking any particular Js Promise framework because it seems many implement the similar specifications (like Promise/A). I've only used Q so far. It seems that in Javascript we call a Deferred the object we resolve to complete a Promise . In Scala, it seems the Promise is the object you