future

How to use reference wrapping for a thread involving a member function of user defined class returning a non void type(c++)

雨燕双飞 提交于 2019-12-12 02:50:42
问题 I'm having trouble making the wait/get future mechanism work with a member function of user defined class returning a non-void type. I wrote a very simple example below, the reference wrapping inside the instruction std::future<int> fut = std::async( &BasicClass::funcInt, std::ref(anObject) ); fails at compile time #include <iostream> // cout #include <future> // async, future using std::cout; using std::async; using std::future; class BasicClass { public: int funcInt(){return 119;} void

Where to put dispatch.Http.shutdown() in case of cascading Http calls

这一生的挚爱 提交于 2019-12-12 01:03:53
问题 At Where to put dispatch.Http.shutdown() I asked where to place the call to dispatch.Http.shutdown() if there are n independent Http calls. Those n independent calls, however, are all on the same "level". How about cascading Http calls , whereas outer1 and outer2 are independent of each other (like in my former question), the inner calls, however, depend on the result of the respective outer call. val outer1 = dispatch.Http(... request1 ...) val outer2 = dispatch.Http(... request2 ...) outer1

Reducing a list of futures

♀尐吖头ヾ 提交于 2019-12-11 23:34:45
问题 I have long running function that returns a future as follows: def longRunningFunction(signs: List[String], numOfWords: Int) : Future[List[(String, Int)]] = Future{ /* computation */ } I need to reduce the output of the Future as follows: val all = (6 to 24).map(i => longRunningFunction(signs, i)) .reduce(_ ::: _) But this does not seem to work. Any thoughts? 回答1: Future.reduce(futures)(_ ::: _) Documentation 回答2: Is this the thing you're looking for? def longRunningFunction(signs: List

How do I apply a limit to the number of bytes read by futures::Stream::concat2?

有些话、适合烂在心里 提交于 2019-12-11 22:27:25
问题 An answer to How do I read the entire body of a Tokio-based Hyper request? suggests: you may wish to establish some kind of cap on the number of bytes read [when using futures::Stream::concat2 ] How can I actually achieve this? For example, here's some code that mimics a malicious user who is sending my service an infinite amount of data: extern crate futures; // 0.1.25 use futures::{prelude::*, stream}; fn some_bytes() -> impl Stream<Item = Vec<u8>, Error = ()> { stream::repeat(b

My PlayFramework Action returns before a Future is ready, how do I update a web page component?

≡放荡痞女 提交于 2019-12-11 20:38:10
问题 I have a Scala PlayFramework function that calls MongoDB and gets a Future[Seq[Document]] result. After a map zoom/pan event, this Play Action function is called from JavaScript on a web page via xhttp/GET. My Action method on the Play side returns before the Future's onComplete/Success is executed. So I'm looking for a way to call a JavaScript function to get the data when the Scala Future's onComplete/Success fires. How would I do that, or am I looking at this wrong? Here is the code in

Waiting at most X seconds for Async EJBs

ぃ、小莉子 提交于 2019-12-11 18:53:13
问题 I have a "client" EJB that invokes 4 Asynchronous EJB s and should give them all 5 seconds to run. After 5 seconds the "client" EJB collects the ready results from Future object that finished running, and returns output. I have a problem with the "waiting" in client part. I tried to invoke future.get(5, TimeUnit.MILLISECONDS) It seems like sometimes async EJB s start to run after the timeout. Is there a correct way to do it? 1) Collect Future objects in Map : Map<String, Future> futureMap =

Convert Single API reponse to a list of Maps to convert to cards in flutter

僤鯓⒐⒋嵵緔 提交于 2019-12-11 17:44:03
问题 I have used the flutter cookbook to create a Future in order to convert a single Map into a card. However I want to do this with a list of Maps. I know I need to create a list and then use the futurebuilder to return a list view, but I am unsure how to add to the apitest() method to add each Map to a list to then convert. Any help is much appreciated. This is main.dart: import 'package:flutter/material.dart'; import './viewviews.dart'; void main() => runApp(new MyApp()); class MyApp extends

Server response with output from Future Object

我是研究僧i 提交于 2019-12-11 16:28:11
问题 i created a async/await function in another file thus its handler is returning a Future Object. Now i can't understand how to give response to client with content of that Future Object in Dart. I am using basic dart server with shelf package.Below is code where ht.handler('list') returns a Future Object and i want to send that string to client as response. But i am getting internal server error. import 'dart:io'; import 'package:args/args.dart'; import 'package:shelf/shelf.dart' as shelf;

Scala Parallel Mergesort - Out of Memory

非 Y 不嫁゛ 提交于 2019-12-11 15:46:55
问题 I've tried to write a parallel Mergesort using Scala Futures. However, when I run my algorithm on a list of size 100 000 inside Eclipse's interpreter everything gets very sluggish and eventually I get an error message telling me I'm out of memory. When I run it in the interpreter from the command line it hangs already at lists of size 10 000 (but now I get no error messages). Why does this happen and is there a fix? import scala.actors.Future import scala.actors.Futures._ object MergeSort{

How do I convert an async / standard library future to futures 0.1?

妖精的绣舞 提交于 2019-12-11 15:41:53
问题 I want to use the async function to parse the inbound stream progressively, but actix-web requires impl Future<Item = HttpResponse, Error = Error> as the return value. How can I convert the future returned by async function to what actix-web requires? I'm using Rust 1.39 nightly and actix-web 1.0.7. http_srv.rs : use futures::compat::Stream01CompatExt; use futures::future::{FutureExt, TryFutureExt}; use futures::stream::TryStreamExt; use futures01::future::Future; use futures01::stream: