Skip to content

Commit 6f2b0b8

Browse files
author
Stjepan Glavina
committed
Make executors scoped
1 parent 19eb3cc commit 6f2b0b8

File tree

4 files changed

+125
-191
lines changed

4 files changed

+125
-191
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ categories = ["asynchronous", "concurrency"]
1313
readme = "README.md"
1414

1515
[dependencies]
16-
async-task = "3.0.0"
16+
async-task = { path = "../async-task" }
1717
concurrent-queue = "1.2.2"
1818
fastrand = "1.3.4"
1919
futures-lite = "1.0.0"
2020
once_cell = "1.4.1"
21+
vec-arena = "1.0.0"
2122

2223
[dev-dependencies]
2324
async-channel = "1.4.1"

examples/priority.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ enum Priority {
1818
/// An executor with task priorities.
1919
///
2020
/// Tasks with lower priorities only get polled when there are no tasks with higher priorities.
21-
struct PriorityExecutor {
22-
ex: [Executor; 3],
21+
struct PriorityExecutor<'a> {
22+
ex: [Executor<'a>; 3],
2323
}
2424

25-
impl PriorityExecutor {
25+
impl<'a> PriorityExecutor<'a> {
2626
/// Creates a new executor.
27-
const fn new() -> PriorityExecutor {
27+
const fn new() -> PriorityExecutor<'a> {
2828
PriorityExecutor {
2929
ex: [Executor::new(), Executor::new(), Executor::new()],
3030
}
3131
}
3232

3333
/// Spawns a task with the given priority.
34-
fn spawn<T: Send + 'static>(
34+
fn spawn<T: Send + 'a>(
3535
&self,
3636
priority: Priority,
37-
future: impl Future<Output = T> + Send + 'static,
37+
future: impl Future<Output = T> + Send + 'a,
3838
) -> Task<T> {
3939
self.ex[priority as usize].spawn(future)
4040
}
@@ -59,7 +59,7 @@ impl PriorityExecutor {
5959
}
6060

6161
fn main() {
62-
static EX: PriorityExecutor = PriorityExecutor::new();
62+
static EX: PriorityExecutor<'_> = PriorityExecutor::new();
6363

6464
// Spawn a thread running the executor forever.
6565
thread::spawn(|| future::block_on(EX.run()));

0 commit comments

Comments
 (0)