pub struct CoroWorker<T, E> { /* private fields */ }Expand description
๐งต โฌก Represents a single-thread stackless coroutine worker.
๐ work/task/coro
It has a private status that can be either running or halted.
Implementationsยง
Sourceยงimpl<T, E> CoroWorker<T, E>
impl<T, E> CoroWorker<T, E>
Sourcepub fn yield_ok(&mut self, value: T) -> CoroWork<'_, T, E> โ
pub fn yield_ok(&mut self, value: T) -> CoroWork<'_, T, E> โ
Yields an Ok value and returns an awaitable CoroWork.
Examples found in repository?
examples/work/coro_manager.rs (line 15)
6fn main() {
7 let mut cr = CoroManager::<char, String>::new();
8
9 for i in 1..=3 {
10 cr.push(|mut c| async move {
11 println!("> instance {i} NEW");
12
13 let mut count = 0;
14 loop {
15 let res = c.yield_ok('a').await?;
16 println!(" instance {i} A.{count} {res:?})");
17
18 let _res = c.yield_ok('b').await?;
19 println!(" instance {i} B {_res:?}");
20
21 if count > 2 {
22 break;
23 }
24 count += 1;
25 }
26
27 println!(" instance {i} BYE!");
28
29 if i == 2 { serr(format!["instance {i} produced an error"]) } else { sok('x') }
30 });
31 }
32 cr.push(|mut c| async move {
33 println!("> instance 4 NEW");
34 for _n in 0..3 {
35 let _res = c.yield_err(format!["custom err"]).await?;
36 }
37 println!(" instance 4 BYE!");
38 None
39 });
40
41 println!("Running");
42 cr.run();
43 println!("Done");
44}Sourcepub fn yield_err(&mut self, error: E) -> CoroWork<'_, T, E> โ
pub fn yield_err(&mut self, error: E) -> CoroWork<'_, T, E> โ
Yields an Err and returns an awaitable CoroWork.
Examples found in repository?
examples/work/coro_manager.rs (line 35)
6fn main() {
7 let mut cr = CoroManager::<char, String>::new();
8
9 for i in 1..=3 {
10 cr.push(|mut c| async move {
11 println!("> instance {i} NEW");
12
13 let mut count = 0;
14 loop {
15 let res = c.yield_ok('a').await?;
16 println!(" instance {i} A.{count} {res:?})");
17
18 let _res = c.yield_ok('b').await?;
19 println!(" instance {i} B {_res:?}");
20
21 if count > 2 {
22 break;
23 }
24 count += 1;
25 }
26
27 println!(" instance {i} BYE!");
28
29 if i == 2 { serr(format!["instance {i} produced an error"]) } else { sok('x') }
30 });
31 }
32 cr.push(|mut c| async move {
33 println!("> instance 4 NEW");
34 for _n in 0..3 {
35 let _res = c.yield_err(format!["custom err"]).await?;
36 }
37 println!(" instance 4 BYE!");
38 None
39 });
40
41 println!("Running");
42 cr.run();
43 println!("Done");
44}Trait Implementationsยง
Sourceยงimpl<T: Clone, E: Clone> Clone for CoroWorker<T, E>
impl<T: Clone, E: Clone> Clone for CoroWorker<T, E>
Sourceยงfn clone(&self) -> CoroWorker<T, E>
fn clone(&self) -> CoroWorker<T, E>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T: Copy, E: Copy> Copy for CoroWorker<T, E>
Auto Trait Implementationsยง
impl<T, E> Freeze for CoroWorker<T, E>
impl<T, E> RefUnwindSafe for CoroWorker<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for CoroWorker<T, E>
impl<T, E> Sync for CoroWorker<T, E>
impl<T, E> Unpin for CoroWorker<T, E>
impl<T, E> UnsafeUnpin for CoroWorker<T, E>where
T: UnsafeUnpin,
E: UnsafeUnpin,
impl<T, E> UnwindSafe for CoroWorker<T, E>where
T: UnwindSafe,
E: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
Returns a deterministic hash of the
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
Available on crate feature
alloc only.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
The alignment of this type in bytes.
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Returns the alignment of this type in bytes.
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Know whether dropping values of this type matters, in compile-time.
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Returns the minimum alignment of the type in bytes. Read more
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Returns the alignment of the pointed-to value in bytes. Read more
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Returns the size of a type in bytes. Read more
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Returns the size of the pointed-to value in bytes. Read more
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
Returns
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
Forgets about
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
Available on crate feature
unsafe_layout only.Returns the value of type
T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
Available on crate feature
unsafe_layout only.Returns the value of type
T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
Available on crate feature
unsafe_slice only.