pub struct Post { /* private fields */ }Expand description
Implementations§
Source§impl Post
impl Post
Sourcepub fn send_command<F>(&self, f: F)
pub fn send_command<F>(&self, f: F)
Sends the given command to ECS scheduler.
Commands are executed on the main worker, but the command is not executed at the time of sending. ECS scheduler runs all buffered commands at the end of current cycle and before the next cycle.
§Examples
use my_ecs::prelude::*;
use std::sync::mpsc;
let (tx, rx) = mpsc::channel();
// A system sending a command.
let tx_a = tx.clone();
let sys_a = move |rr: ResRead<Post>| {
tx_a.send("sys_a").unwrap();
let tx_aa = tx_a.clone();
rr.send_command(move |ecs| {
tx_aa.send("cmd_a").unwrap();
Ok(())
});
};
// A system sending a command.
let tx_b = tx.clone();
let sys_b = move |rr: ResRead<Post>| {
tx_b.send("sys_b").unwrap();
let tx_bb = tx_b.clone();
rr.send_command(move |ecs| {
tx_bb.send("cmd_b").unwrap();
Ok(())
});
};
Ecs::default(WorkerPool::with_len(2), [2])
.add_systems((sys_a, sys_b))
.step();
// No data dependency between `sys_a` and `sys_b`, so they can be run
// simultaneously.
assert!(matches!(rx.try_recv(), Ok("sys_a") | Ok("sys_b")));
assert!(matches!(rx.try_recv(), Ok("sys_a") | Ok("sys_b")));
assert!(matches!(rx.try_recv(), Ok("cmd_a") | Ok("cmd_b")));
assert!(matches!(rx.try_recv(), Ok("cmd_a") | Ok("cmd_b")));Sourcepub fn send_future<F, R>(&self, future: F)
pub fn send_future<F, R>(&self, future: F)
Sends the given future to ECS scheduler.
The future is guaranteed to be polled more than or just once in the current cycle.
§Examples
use my_ecs::prelude::*;
use std::{time::Duration, sync::{Arc, Mutex}};
let state = Arc::new(Mutex::new(0));
let c_state = Arc::clone(&state);
let foo = async move {
*c_state.lock().unwrap() = 1;
async_io::Timer::after(Duration::from_millis(10)).await;
*c_state.lock().unwrap() = 2;
};
Ecs::default(WorkerPool::new(), [])
.add_once_system(move |rr: ResRead<Post>| {
rr.send_future(foo);
})
.run(|_| {});
assert_eq!(*state.lock().unwrap(), 2);pub fn request_lock<'buf, Req>(&self) -> RequestLockFuture<'buf, Req>where
Req: Request,
pub fn change_entity(&self, eid: EntityId) -> EntityMoveCommandBuilder<'_>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Post
impl RefUnwindSafe for Post
impl Send for Post
impl Sync for Post
impl Unpin for Post
impl UnwindSafe for Post
Blanket Implementations§
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more