future

how to get Future return when cause timeout Exception in java

一世执手 提交于 2021-02-20 00:47:56
问题 I'm wondering can I get the result when it cause timeout Exception when use Future and ExecutorService, for example, below is my code package com.example; import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.apache.commons.lang3.concurrent

how to get Future return when cause timeout Exception in java

房东的猫 提交于 2021-02-20 00:42:09
问题 I'm wondering can I get the result when it cause timeout Exception when use Future and ExecutorService, for example, below is my code package com.example; import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.apache.commons.lang3.concurrent

How to run multiple futures that call thread::sleep in parallel? [duplicate]

帅比萌擦擦* 提交于 2021-02-16 13:15:32
问题 This question already has answers here : Why does Future::select choose the future with a longer sleep period first? (1 answer) What is the best approach to encapsulate blocking I/O in future-rs? (1 answer) Closed 2 years ago . I have a slow future that blocks for 1 second before running to completion. I've tried to use the join combinator but the composite future my_app executes the futures sequentially: #![feature(pin, futures_api, arbitrary_self_types)] extern crate futures; // v0.3 use

Why do I not get a wakeup for multiple futures when they use the same underlying socket?

梦想与她 提交于 2021-02-11 04:54:57
问题 I have code which sends data to multiple UDP endpoints using same local UdpSocket: use futures::stream::FuturesUnordered; use futures::StreamExt; use std::{ future::Future, net::{Ipv4Addr, SocketAddr}, pin::Pin, task::{Context, Poll}, }; use tokio::net::UdpSocket; #[tokio::main] async fn main() { let server_0: SocketAddr = (Ipv4Addr::UNSPECIFIED, 12000).into(); let server_2: SocketAddr = (Ipv4Addr::UNSPECIFIED, 12002).into(); let server_1: SocketAddr = (Ipv4Addr::UNSPECIFIED, 12001).into();

How do I conditionally return different types of futures?

无人久伴 提交于 2021-02-10 17:27:32
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |

How do I conditionally return different types of futures?

柔情痞子 提交于 2021-02-10 17:27:28
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |

How do I conditionally return different types of futures?

[亡魂溺海] 提交于 2021-02-10 17:25:21
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |

How do I conditionally return different types of futures?

元气小坏坏 提交于 2021-02-10 17:25:09
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |

How do I conditionally return different types of futures?

人盡茶涼 提交于 2021-02-10 17:24:48
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |

How do I conditionally return different types of futures?

给你一囗甜甜゛ 提交于 2021-02-10 17:24:27
问题 I have a method that, depending on a predicate, will return one future or another. In other words, an if-else expression that returns a future: extern crate futures; // 0.1.23 use futures::{future, Future}; fn f() -> impl Future<Item = usize, Error = ()> { if 1 > 0 { future::ok(2).map(|x| x) } else { future::ok(10).and_then(|x| future::ok(x + 2)) } } This doesn't compile: error[E0308]: if and else have incompatible types --> src/lib.rs:6:5 | 6 | / if 1 > 0 { 7 | | future::ok(2).map(|x| x) 8 |