Skip to content

Commit

Permalink
build: update examples for 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Dec 2, 2024
1 parent 9cfff02 commit f837f8b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions examples/cross_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use async_std::task::sleep;
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*, tasks::AsyncComputeTaskPool};
use bevy_async_task::{AsyncReceiver, AsyncTask};
use std::time::Duration;
use bevy_async_task::{AsyncReceiver, AsyncTask, Duration};

#[derive(Resource, DerefMut, Deref, Default)]
struct MyTask(Option<AsyncReceiver<u32>>);
Expand All @@ -16,7 +15,7 @@ async fn long_task() -> u32 {
}

fn system1_start(mut my_task: ResMut<'_, MyTask>) {
let (fut, receiver) = AsyncTask::new(long_task()).into_parts();
let (fut, receiver) = AsyncTask::new(long_task()).build();
my_task.replace(receiver);
AsyncComputeTaskPool::get().spawn_local(fut).detach();
info!("Started!");
Expand All @@ -27,12 +26,13 @@ fn system2_poll(mut my_task: ResMut<'_, MyTask>) {
return;
};
match receiver.try_recv() {
Some(v) => {
Some(Ok(v)) => {
info!("Received {v}");
}
None => {
// Waiting...
}
_ => unreachable!(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use async_std::task::sleep;
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*};
use bevy_async_task::AsyncTaskPool;
use std::{task::Poll, time::Duration};
use bevy_async_task::{AsyncTaskPool, Duration};
use std::task::Poll;

fn system1(mut task_pool: AsyncTaskPool<'_, u64>) {
if task_pool.is_idle() {
Expand All @@ -17,7 +17,7 @@ fn system1(mut task_pool: AsyncTaskPool<'_, u64>) {
}

for status in task_pool.iter_poll() {
if let Poll::Ready(t) = status {
if let Poll::Ready(Ok(t)) = status {
info!("Received {t}");
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ fn my_system(mut task_runner: AsyncTaskRunner<'_, u32>) {
}

match task_runner.poll() {
Poll::Ready(v) => {
Poll::Ready(Ok(v)) => {
info!("Received {v}");
}
Poll::Pending => {
// Waiting...
}
_ => unreachable!(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use async_std::{future::pending, task::sleep};
use bevy::{app::PanicHandlerPlugin, log::LogPlugin, prelude::*};
use bevy_async_task::{AsyncTask, AsyncTaskRunner, TaskError};
use std::{task::Poll, time::Duration};
use bevy_async_task::{AsyncTask, AsyncTaskRunner, Duration, TaskError};
use std::task::Poll;

fn system_does_timeout(mut task_executor: AsyncTaskRunner<'_, Result<(), TaskError>>) {
fn system_does_timeout(mut task_executor: AsyncTaskRunner<'_, ()>) {
if task_executor.is_idle() {
let timeout_task = AsyncTask::new_with_timeout(Duration::from_secs(1), pending());
task_executor.start(timeout_task);
Expand All @@ -23,7 +23,7 @@ fn system_does_timeout(mut task_executor: AsyncTaskRunner<'_, Result<(), TaskErr
}
}

fn system_doesnt_timeout(mut task_executor: AsyncTaskRunner<'_, Result<u32, TaskError>>) {
fn system_doesnt_timeout(mut task_executor: AsyncTaskRunner<'_, u32>) {
if task_executor.is_idle() {
let timeout_task = AsyncTask::new_with_timeout(Duration::from_secs(10), async {
sleep(Duration::from_secs(2)).await;
Expand Down

0 comments on commit f837f8b

Please sign in to comment.