当使用Async.StartAsTask在F#中包装异步操作时,返回的类型将是Task<unit>.这使得接口的用户依赖于F#核心库.是否有建议的做法来避免这种情况,或者通常是否接受将其置于默认状态?
我有一个Framed使用LinesCodec.
当我尝试将其包装在测试中时,大约有 20% 的时间会阻塞未来,但是因为我没有在尝试连接的套接字上侦听任何内容,所以我希望总是得到错误:
thread 'tokio-runtime-worker-0' panicked at 'error: Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }', src/lib.rs:35:24 note: Run with 'RUST_BACKTRACE=1' for a backtrace.
Run Code Online (Sandbox Code Playgroud)
这是我使用的测试代码:
#[macro_use(try_ready)]
extern crate futures; // 0.1.24
extern crate tokio; // 0.1.8
use std::io;
use std::net::SocketAddr;
use tokio::codec::{Framed, LinesCodec};
use tokio::net::TcpStream;
use tokio::prelude::*;
struct MyFuture {
addr: SocketAddr,
}
impl Future for MyFuture {
type Item = Framed<TcpStream, LinesCodec>;
type Error = io::Error;
fn poll(&mut self) -> Result<Async<Framed<TcpStream, LinesCodec>>, …Run Code Online (Sandbox Code Playgroud)