export Task and take advantage of interior mutability

This commit is contained in:
Dark 2023-02-12 21:37:26 -05:00
parent 24edd79806
commit 11670a8216
Signed by: Dark
GPG key ID: 8910EE89544A1676
2 changed files with 6 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "synergetic"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "Minimal tick-based async executor for constrained environments"
license = "MIT"

View file

@ -50,7 +50,7 @@ use alloc::sync::Arc;
use alloc::vec::Vec;
use async_task::Runnable;
use async_task::Task;
pub use async_task::Task;
#[cfg(feature = "spin")]
use spin::Mutex;
@ -76,7 +76,7 @@ impl Executor {
///
/// Any future running in the executor that passes its `Waker` to another
/// thread will cause UB.
pub unsafe fn spawn<F>(&mut self, future: F) -> Task<F::Output>
pub unsafe fn spawn<F>(&self, future: F) -> Task<F::Output>
where
F: Future + 'static,
{
@ -96,7 +96,7 @@ impl Executor {
///
/// Any future running in the executor that passes its `Waker` to another
/// thread will cause UB.
pub unsafe fn tick(&mut self) {
pub unsafe fn tick(&self) {
let mut queue_guard = self.queue.borrow_mut();
let mut tasks: Vec<_> = queue_guard.drain(..).collect();
drop(queue_guard);
@ -139,7 +139,7 @@ impl LockingExecutor {
}
/// Spawns a new task in the executor.
pub fn spawn<F>(&mut self, future: F) -> Task<F::Output>
pub fn spawn<F>(&self, future: F) -> Task<F::Output>
where
F: Future + 'static + Send + Sync,
<F as Future>::Output: Send,
@ -155,7 +155,7 @@ impl LockingExecutor {
}
/// Runs a single tick of the executor.
pub fn tick(&mut self) {
pub fn tick(&self) {
let mut queue_guard = self.queue.lock();
let mut tasks: Vec<_> = queue_guard.drain(..).collect();
drop(queue_guard);