Skip to content

Commit 51d01f7

Browse files
authored
Remove TickedAsyncExecutor::spawn API (#6)
1 parent 45c76da commit 51d01f7

File tree

3 files changed

+21
-40
lines changed

3 files changed

+21
-40
lines changed

.github/workflows/rust.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
token: ${{ secrets.CODECOV_TOKEN }}
4747
files: target/cobertura.xml
4848

49-
- name: Miri
50-
run: |
51-
rustup toolchain install nightly --component miri
52-
rustup override set nightly
53-
cargo miri setup
54-
cargo miri test
49+
# - name: Miri
50+
# run: |
51+
# rustup toolchain install nightly --component miri
52+
# rustup override set nightly
53+
# cargo miri setup
54+
# cargo miri test

src/ticked_async_executor.rs

+11-30
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Payload = (TaskIdentifier, async_task::Runnable);
2222
pub struct TickedAsyncExecutor<O> {
2323
channel: (mpsc::Sender<Payload>, mpsc::Receiver<Payload>),
2424
num_woken_tasks: Arc<AtomicUsize>,
25+
2526
num_spawned_tasks: Arc<AtomicUsize>,
2627

2728
// TODO, Or we need a Single Producer - Multi Consumer channel i.e Broadcast channel
@@ -52,22 +53,6 @@ where
5253
}
5354
}
5455

55-
pub fn spawn<T>(
56-
&self,
57-
identifier: impl Into<TaskIdentifier>,
58-
future: impl Future<Output = T> + Send + 'static,
59-
) -> Task<T>
60-
where
61-
T: Send + 'static,
62-
{
63-
let identifier = identifier.into();
64-
let future = self.droppable_future(identifier.clone(), future);
65-
let schedule = self.runnable_schedule_cb(identifier);
66-
let (runnable, task) = async_task::spawn(future, schedule);
67-
runnable.schedule();
68-
task
69-
}
70-
7156
pub fn spawn_local<T>(
7257
&self,
7358
identifier: impl Into<TaskIdentifier>,
@@ -172,7 +157,7 @@ mod tests {
172157
fn test_multiple_tasks() {
173158
let executor = TickedAsyncExecutor::default();
174159
executor
175-
.spawn("A", async move {
160+
.spawn_local("A", async move {
176161
tokio::task::yield_now().await;
177162
})
178163
.detach();
@@ -226,15 +211,6 @@ mod tests {
226211
fn test_ticked_timer() {
227212
let executor = TickedAsyncExecutor::default();
228213

229-
for _ in 0..10 {
230-
let timer: TickedTimer = executor.create_timer();
231-
executor
232-
.spawn("ThreadedTimer", async move {
233-
timer.sleep_for(256.0).await;
234-
})
235-
.detach();
236-
}
237-
238214
for _ in 0..10 {
239215
let timer = executor.create_timer();
240216
executor
@@ -255,25 +231,30 @@ mod tests {
255231
let elapsed = now.elapsed();
256232
println!("Elapsed: {:?}", elapsed);
257233
println!("Total: {:?}", instances);
234+
println!(
235+
"Min: {:?}, Max: {:?}",
236+
instances.iter().min(),
237+
instances.iter().max()
238+
);
258239

259240
// Test Timer cancellation
260241
let timer = executor.create_timer();
261242
executor
262-
.spawn("ThreadedFuture", async move {
243+
.spawn_local("LocalFuture1", async move {
263244
timer.sleep_for(1000.0).await;
264245
})
265246
.detach();
266247

267248
let timer = executor.create_timer();
268249
executor
269-
.spawn_local("LocalFuture", async move {
250+
.spawn_local("LocalFuture2", async move {
270251
timer.sleep_for(1000.0).await;
271252
})
272253
.detach();
273254

274255
let mut tick_event = executor.tick_channel();
275256
executor
276-
.spawn("ThreadedTickFuture", async move {
257+
.spawn_local("LocalTickFuture1", async move {
277258
loop {
278259
let _r = tick_event.changed().await;
279260
if _r.is_err() {
@@ -285,7 +266,7 @@ mod tests {
285266

286267
let mut tick_event = executor.tick_channel();
287268
executor
288-
.spawn_local("LocalTickFuture", async move {
269+
.spawn_local("LocalTickFuture2", async move {
289270
loop {
290271
let _r = tick_event.changed().await;
291272
if _r.is_err() {

tests/tokio_tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn test_tokio_join() {
99
let (tx1, mut rx1) = tokio::sync::mpsc::channel::<usize>(1);
1010
let (tx2, mut rx2) = tokio::sync::mpsc::channel::<usize>(1);
1111
executor
12-
.spawn("ThreadedFuture", async move {
12+
.spawn_local("LocalFuture1", async move {
1313
let (a, b) = tokio::join!(rx1.recv(), rx2.recv());
1414
assert_eq!(a.unwrap(), 10);
1515
assert_eq!(b.unwrap(), 20);
@@ -19,7 +19,7 @@ fn test_tokio_join() {
1919
let (tx3, mut rx3) = tokio::sync::mpsc::channel::<usize>(1);
2020
let (tx4, mut rx4) = tokio::sync::mpsc::channel::<usize>(1);
2121
executor
22-
.spawn("LocalFuture", async move {
22+
.spawn_local("LocalFuture2", async move {
2323
let (a, b) = tokio::join!(rx3.recv(), rx4.recv());
2424
assert_eq!(a.unwrap(), 10);
2525
assert_eq!(b.unwrap(), 20);
@@ -46,7 +46,7 @@ fn test_tokio_select() {
4646
let (tx1, mut rx1) = tokio::sync::mpsc::channel::<usize>(1);
4747
let (_tx2, mut rx2) = tokio::sync::mpsc::channel::<usize>(1);
4848
executor
49-
.spawn("ThreadedFuture", async move {
49+
.spawn_local("LocalFuture1", async move {
5050
tokio::select! {
5151
data = rx1.recv() => {
5252
assert_eq!(data.unwrap(), 10);
@@ -59,7 +59,7 @@ fn test_tokio_select() {
5959
let (tx3, mut rx3) = tokio::sync::mpsc::channel::<usize>(1);
6060
let (_tx4, mut rx4) = tokio::sync::mpsc::channel::<usize>(1);
6161
executor
62-
.spawn("LocalFuture", async move {
62+
.spawn_local("LocalFuture2", async move {
6363
tokio::select! {
6464
data = rx3.recv() => {
6565
assert_eq!(data.unwrap(), 10);

0 commit comments

Comments
 (0)