随笔分类 -  Tokio

摘要:环境 Time 2022-01-12 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/io/struct.Stdout.html 示例 main.rs use tokio::io::{self, AsyncBufRe 阅读全文
posted @ 2022-03-30 09:34 jiangbo4444 阅读(191) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/time/index.html 示例 interval use std::{io, thread, time::Duration} 阅读全文
posted @ 2022-03-30 09:21 jiangbo4444 阅读(324) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/time/index.html 标准库和 Tokio 都提供了线程休眠函数 sleep,标准库的休眠会挂起线程,不做任何事。而 T 阅读全文
posted @ 2022-03-30 09:19 jiangbo4444 阅读(705) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/task/index.html 示例 正常结果 use std::{io, thread}; #[tokio::main] asy 阅读全文
posted @ 2022-03-30 09:18 jiangbo4444 阅读(304) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/time/index.html 示例 timeout use std::io; use tokio::time::{self, D 阅读全文
posted @ 2022-03-30 09:17 jiangbo4444 阅读(541) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/task/index.html 运行阻塞任务可以有两种选择,spawn_blocking 和 block_in_place。前面说 阅读全文
posted @ 2022-03-30 09:16 jiangbo4444 阅读(329) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/time/struct.Instant.html 示例 main.rs use std::{io, time::Duration} 阅读全文
posted @ 2022-03-30 09:15 jiangbo4444 阅读(116) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/signal/index.html Tokio 可以异步接收系统传递的信号。 示例 main.rs 按下 ctrl-c 时,程序结 阅读全文
posted @ 2022-03-30 09:14 jiangbo4444 阅读(140) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/attr.main.html 除了使用明确编写代码来新建运行时,也可以使用宏来创建。 示例 main.rs use std::{i 阅读全文
posted @ 2022-03-30 09:13 jiangbo4444 阅读(223) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/task/index.html yield_now 可以放弃当前的执行时间片。 示例 main.rs use std::{io, 阅读全文
posted @ 2022-03-30 09:12 jiangbo4444 阅读(125) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 默认情况下,Tokio 启动的工作线程数和 CPU 核数相等,也可以自定义 阅读全文
posted @ 2022-02-28 19:31 jiangbo4444 阅读(1104) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 除了使用 new 直接创建的方式,还可以使用 Builder 来构建运行时 阅读全文
posted @ 2022-02-28 19:31 jiangbo4444 阅读(93) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 在线程空闲和运行时,可以定义一个回调。 示例 main.rs use st 阅读全文
posted @ 2022-02-28 19:30 jiangbo4444 阅读(93) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 通过 thread_name 和 thread_name_fn 可以对线程 阅读全文
posted @ 2022-02-28 19:30 jiangbo4444 阅读(256) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 对于阻塞任务,Tokio 会新启动一个线程来运行,可以设置启动的最大线程数 阅读全文
posted @ 2022-02-28 19:29 jiangbo4444 阅读(407) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 对于阻塞任务,Tokio 会新启动一个线程来运行,这个也是在一个线程池中, 阅读全文
posted @ 2022-02-28 19:29 jiangbo4444 阅读(95) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 在线程启动和结束时,可以定义一个回调。 示例 main.rs use st 阅读全文
posted @ 2022-02-28 19:28 jiangbo4444 阅读(108) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 除了可以使用线程池运行时,还可以直接在当前线程运行任务,使用单线程。 示例 阅读全文
posted @ 2022-02-27 21:55 jiangbo4444 阅读(344) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html Tokio 除了是一个异步运行时外,还提供了其它方面的功能,可以进行开启。 阅读全文
posted @ 2022-02-27 21:55 jiangbo4444 阅读(105) 评论(0) 推荐(0) 编辑
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html handle 方法返回一个可以执行任务的句柄。 示例 main.rs us 阅读全文
posted @ 2022-02-27 21:54 jiangbo4444 阅读(87) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示