Skip to content

Commit

Permalink
Rename Join to Loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Feb 19, 2023
1 parent 7db9a58 commit 5bc14ba
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::time::Duration;

use async_main::{async_main, LocalSpawner};
use async_std::task::sleep;
use pasts::{notify, prelude::*, Join};
use pasts::{notify, prelude::*, Loop};

// Exit type for App.
struct Exit;
Expand Down Expand Up @@ -43,7 +43,7 @@ async fn main(_spawner: LocalSpawner) {
two: &mut notify::future_fn(|| Box::pin(sleep(2.0))),
};

Join::new(&mut app)
Loop::new(&mut app)
.on(|s| s.one, App::one)
.on(|s| s.two, App::two)
.await;
Expand Down
4 changes: 2 additions & 2 deletions examples/no-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate alloc;

use async_main::{async_main, LocalSpawner};
use pasts::{prelude::*, Join};
use pasts::{prelude::*, Loop};

struct State {
// Spawned tasks
Expand Down Expand Up @@ -40,7 +40,7 @@ async fn main(_spawner: LocalSpawner) {
tasks: [task_one, task_two],
};

Join::new(state)
Loop::new(state)
.on(|s| s.tasks.as_mut_slice(), State::task_done)
.await;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/slices.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_main::{async_main, LocalSpawner};
use pasts::{prelude::*, Join};
use pasts::{prelude::*, Loop};

struct Exit;

Expand All @@ -24,5 +24,5 @@ async fn main(_spawner: LocalSpawner) {
let mut app = App { tasks };

// First task will complete first.
Join::new(&mut app).on(|s| s.tasks, App::completion).await;
Loop::new(&mut app).on(|s| s.tasks, App::completion).await;
}
4 changes: 2 additions & 2 deletions examples/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_main::{async_main, LocalSpawner};
use pasts::{prelude::*, Join};
use pasts::{prelude::*, Loop};

struct Exit;

Expand Down Expand Up @@ -30,7 +30,7 @@ async fn main(_spawner: LocalSpawner) {
],
};

Join::new(&mut app)
Loop::new(&mut app)
.on(|s| &mut s.tasks[..], App::completion)
.await;
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ extern crate alloc;

pub mod notify;

mod join;
mod r#loop;
mod spawn;

use self::prelude::*;
pub use self::{
join::Join,
r#loop::Loop,
spawn::{Executor, Park, Pool, Spawn},
};

Expand Down
20 changes: 10 additions & 10 deletions src/join.rs → src/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ impl<S, T> Stateful<S, T> for Never<'_, S> {
#[doc = include_str!("../examples/tasks.rs")]
/// ```
#[derive(Debug)]
pub struct Join<S: Unpin, T, F: Stateful<S, T>> {
pub struct Loop<S: Unpin, T, F: Stateful<S, T>> {
other: F,
_phantom: core::marker::PhantomData<(S, T)>,
}

impl<'a, S: Unpin, T> Join<S, T, Never<'a, S>> {
impl<'a, S: Unpin, T> Loop<S, T, Never<'a, S>> {
/// Create an empty event loop.
pub fn new(state: &'a mut S) -> Self {
let other = Never(state);
let _phantom = core::marker::PhantomData;

Join { other, _phantom }
Loop { other, _phantom }
}
}

impl<S: Unpin, T, F: Stateful<S, T>> Join<S, T, F> {
impl<S: Unpin, T, F: Stateful<S, T>> Loop<S, T, F> {
/// Register an event handler.
pub fn on<N: Notify + Unpin + ?Sized>(
self,
noti: impl for<'a> FnMut(&'a mut S) -> &'a mut N + Unpin,
then: fn(&mut S, N::Event) -> Poll<T>,
) -> Join<S, T, impl Stateful<S, T>> {
) -> Loop<S, T, impl Stateful<S, T>> {
let other = self.other;
let _phantom = core::marker::PhantomData;
let other = Joiner { other, noti, then };
let other = Looper { other, noti, then };

Join { other, _phantom }
Loop { other, _phantom }
}
}

impl<S: Unpin, T: Unpin, F: Stateful<S, T>> Future for Join<S, T, F> {
impl<S: Unpin, T: Unpin, F: Stateful<S, T>> Future for Loop<S, T, F> {
type Output = T;

#[inline]
Expand All @@ -77,13 +77,13 @@ impl<S: Unpin, T: Unpin, F: Stateful<S, T>> Future for Join<S, T, F> {
}
}

struct Joiner<S, T, E, F: Stateful<S, T>, P> {
struct Looper<S, T, E, F: Stateful<S, T>, P> {
other: F,
noti: P,
then: fn(&mut S, E) -> Poll<T>,
}

impl<S, T, E, F, N, P> Stateful<S, T> for Joiner<S, T, E, F, P>
impl<S, T, E, F, N, P> Stateful<S, T> for Looper<S, T, E, F, P>
where
F: Stateful<S, T>,
N: Notify<Event = E> + Unpin + ?Sized,
Expand Down

0 comments on commit 5bc14ba

Please sign in to comment.