future

Sorting based on Future Result

混江龙づ霸主 提交于 2019-12-02 13:55:41
问题 I've trying to sort a list by a future boolean. I have a list of IDs and I need to query an external service to find out if there's contextual information behind them. The method I use to do this returns an optional future. By using the partition method I hoped to create two lists of IDs, one with contextual information and one without. The following answer on here provided a lot of help for this: Scala - sort based on Future result predicate I now have an rough, untested method that looks

How to use take_while with futures::Stream?

爱⌒轻易说出口 提交于 2019-12-02 11:58:40
I'm trying to understand what syntax should I use for take_while() with futures::Stream; crate (0.1.25). Here's a piece of code ( on playground ): use futures::{stream, Stream}; // 0.1.25 fn into_many(i: i32) -> impl Stream<Item = i32, Error = ()> { stream::iter_ok(0..i) } fn main() { println!("start:"); let _ = into_many(10) // .take_while(|x| { x < 10 }) .map(|x| { println!("number={}", x); x }) .wait(); for _ in foo {} // ← this (by @mcarton) println!("finish:"); } The main goal is to determine the right combinations of operators/commands to run the presented playground successfully with

Flutter/Dart - calling a function that is a Future<String> … but needs to return only a String

梦想的初衷 提交于 2019-12-02 05:45:12
I have an async function that is calling out to Firestore to pull in a data value. I got a lot of help in a previous post...learned a lot...and wanted to start over with hopefully a cleaner question. So I have the following function Future<String> getSetList () async { DocumentReference set01DocRef = Firestore.instance.collection('sets').document('SET01'); var snapshot = await set01DocRef.get(); songList = snapshot['songs']; //works, get expected text value from FS return songList; } This function logic works...I can print() out the songList var (string var) to the console and I see the value

Sorting based on Future Result

不想你离开。 提交于 2019-12-02 04:53:40
I've trying to sort a list by a future boolean. I have a list of IDs and I need to query an external service to find out if there's contextual information behind them. The method I use to do this returns an optional future. By using the partition method I hoped to create two lists of IDs, one with contextual information and one without. The following answer on here provided a lot of help for this: Scala - sort based on Future result predicate I now have an rough, untested method that looks like so, val futureMatch = listOfIds.map( b => b.map{ j => getContext(j).map{ k => Map( j -> k) } }).map

How to invoke a method again and again until it returns a `Future` value containing `None`

杀马特。学长 韩版系。学妹 提交于 2019-12-02 04:49:31
问题 Given a method that returns a Future like this... def remove(id: String): Future[Option[User]] = Future { // removes and returns the user identified by `id` } ... how do I invoke it again and again until it returns a Future value containing None ? EDIT Perhaps it is worth to mention that I don't need to collect the results. I just need to invoke the method as long as it finds an user to remove. The idea would be to have a loop that stops when remove returns Future[None] . 回答1: Someone

std::async function running serially

妖精的绣舞 提交于 2019-12-02 04:11:25
When using std::async with launch::async in a for loop, my code runs serially in the same thread, as if each async call waits for the previous before launching. In the notes for std::async references ( std::async ), this is possible if the std::future is not bound to a reference, but that's not the case with my code. Can anyone figure out why it's running serially? Here is my code snippet: class __DownloadItem__ { //DownloadItem is just a "typedef shared_ptr<__DownloadItem__> DownloadItem" std::string buffer; time_t last_access; std::shared_future<std::string> future; } for(uint64_t start:

How to invoke a method again and again until it returns a `Future` value containing `None`

本小妞迷上赌 提交于 2019-12-02 04:03:06
Given a method that returns a Future like this... def remove(id: String): Future[Option[User]] = Future { // removes and returns the user identified by `id` } ... how do I invoke it again and again until it returns a Future value containing None ? EDIT Perhaps it is worth to mention that I don't need to collect the results. I just need to invoke the method as long as it finds an user to remove. The idea would be to have a loop that stops when remove returns Future[None] . Someone commented earlier that there's no point. The surprise for me was that there's no quickie for lazily consuming the

ExecutorService Future::get very slow

假如想象 提交于 2019-12-02 03:49:24
问题 I'm parallelizing a quite complex program to get it faster. For this I use most of the time the ExecutorService . Until now it worked pretty well, but then I noticed that just one line of code makes my program run half as fast as it could. It's the line with exactScore.get() . I don't know why, but it sometimes needs more that 0.1 s just to get the double value of the Future Object. Why is this? How can I handle it that it runs faster? Is there a way to write directly in the Double[] while

boost::future and continuations - value set, but future still blocks

霸气de小男生 提交于 2019-12-02 02:08:52
I am trying to make the following continuation work - but f.get() blocks. Whats wrong? #include <iostream> #define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION #include <boost/thread/future.hpp> struct Foo { boost::future<int> start() { return p.get_future(); } void finish() { p.set_value(23); } boost::promise<int> p; }; int main () { Foo foo; foo.start().then([](boost::future<int> f) { std::cout << "done:" << std::endl; std::cout << f.get() << std::endl; }); foo.finish(); } It'll print the "done:" , so the future fires, but it'll then just "hang" on f.get() .

ExecutorService Future::get very slow

纵然是瞬间 提交于 2019-12-01 23:32:52
I'm parallelizing a quite complex program to get it faster. For this I use most of the time the ExecutorService . Until now it worked pretty well, but then I noticed that just one line of code makes my program run half as fast as it could. It's the line with exactScore.get() . I don't know why, but it sometimes needs more that 0.1 s just to get the double value of the Future Object. Why is this? How can I handle it that it runs faster? Is there a way to write directly in the Double[] while multithreading? Thanks int processors = Runtime.getRuntime().availableProcessors(); ExecutorService