Comments (5)
almost exactly the semantics I want (the exact semantics would require
select!
shenanigans).
Did you see try_join
?
from tokio-uring.
Yeah, try_join
is close, but it doesn't support graceful cancellation. Here's what I came up with for my use-case (hiding behind details to not distract from the main idea of "structured concurrency works with thread-per-core"):
pub async fn try_par<E, F1, F2>(token: &CancellationToken, f1: F1, f2: F2) -> Result<(), E>
where
F1: Future<Output = Result<(), E>>,
F2: Future<Output = Result<(), E>>,
{
let f1 = f1.fuse();
let f2 = f2.fuse();
tokio::pin!(f1, f2);
let mut rs: [Option<Result<(), E>>; 2] = [None, None];
loop {
rs = match rs {
[Some(r1), Some(r2)] => return r1.or(r2),
_ => rs,
};
let (r, _) = futures_util::future::select(&mut f1, &mut f2).await.factor_first();
if r.is_err() {
token.cancel();
}
*if rs[0].is_none() { &mut rs[0] } else { &mut rs[1] } = Some(r);
}
}
from tokio-uring.
@matklad I'm not sure really that this falls within the scope of tokio-uring. IMO the goal of tokio-uring is to figure out the kinks and quirks of io_uring and work things out from an API perspective before eventually implementing the finalized API into tokio. In particular it would be great to get the API to work on the multi threaded runtime.
I think a better place for this would be in tokio-util or tokio itself. You could probably build something around localsets that would work for this.
from tokio-uring.
Closing this as its probably a better question for the broader tokio project.
from tokio-uring.
For posterity, the API along these lines was implemented in the moro crate: https://github.com/nikomatsakis/moro
from tokio-uring.
Related Issues (20)
- Proposal for overhaul of buffer representation HOT 11
- multi_thread support HOT 5
- Direct IO HOT 2
- Support _msg syscalls HOT 4
- impl Clone for stream types?
- Add chunks() for BoundedBuf
- Not in a runtime context is not always true HOT 5
- Return msghdr from `recvmsg`
- DPDK support? HOT 5
- Dead or dying? HOT 9
- Support for windows IOCP (input/output completion ports) another completion-based async API HOT 1
- Is it support `splice` operation now?
- New Release? HOT 3
- tokio-uring missing similar tokio runtime builder options
- io_uring command support? HOT 3
- Support for IO_LINK feature
- Restructuring HOT 2
- __io_uring_buf_ring_cq_advance broken? HOT 1
- [BUG] Hangs when using iopoll without sqpoll HOT 2
- Expose access to io_uring in the form of submission and completion queues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokio-uring.