Use new values api (#521)

This commit is contained in:
Nikolay Kim 2025-03-13 17:42:59 +05:00 committed by GitHub
parent cfc32ed74f
commit ab5fb624b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 79 deletions

View file

@ -52,28 +52,22 @@ struct StreamOpsInner<T> {
impl<T: AsRawFd + 'static> StreamOps<T> {
pub(crate) fn current() -> Self {
Runtime::with_current(|rt| {
if let Some(s) = rt.get::<Self>() {
s
} else {
let mut inner = None;
rt.driver().register(|api| {
let ops = Rc::new(StreamOpsInner {
api,
feed: Cell::new(Some(VecDeque::new())),
streams: Cell::new(Some(Box::new(Slab::new()))),
});
inner = Some(ops.clone());
Box::new(StreamOpsHandler {
inner: ops,
feed: VecDeque::new(),
})
Runtime::value(|rt| {
let mut inner = None;
rt.driver().register(|api| {
let ops = Rc::new(StreamOpsInner {
api,
feed: Cell::new(Some(VecDeque::new())),
streams: Cell::new(Some(Box::new(Slab::new()))),
});
inner = Some(ops.clone());
Box::new(StreamOpsHandler {
inner: ops,
feed: VecDeque::new(),
})
});
let s = StreamOps(inner.unwrap());
rt.insert(s.clone());
s
}
StreamOps(inner.unwrap())
})
}