4 个稳定版本
1.3.0 | 2021 年 4 月 2 日 |
---|---|
1.2.0 | 2021 年 4 月 2 日 |
1.1.0 | 2021 年 4 月 1 日 |
1.0.0 | 2021 年 3 月 27 日 |
#2102 在 异步
16KB
193 行
entangled
entangled 提供了一个基于 async-executor crate 的线程池,用于在异步 future 上进行 spawn。
它的主要特点是可以“范围启动”功能,这实际上是从主线程分叉任务,这些任务可以访问主线程的栈,并在完成后再将它们连接起来。
示例
use entangled::*;
use std::sync::atomic::*;
fn main() {
let pool = ThreadPool::new(
ThreadPoolDescriptor::default()
).expect("can't create task pool");
let counter = AtomicI32::new(0);
let ref_counter = &counter;
pool.scope(|scope| {
for _ in 0..10 {
scope.spawn(async {
ref_counter.fetch_add(1, Ordering::Relaxed);
});
}
});
assert_eq!(counter.load(Ordering::Relaxed), 10);
}
致谢
最初基于 bevy_tasks crate,但完全使用版本 1.2 重写
许可证
Apache-2.0 或 MIT 或 ZLIB 许可
依赖关系
~1MB
~13K SLoC