-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Addresses are sinks POC (based on flume changes) * Add a debug implementation for Address (#67) * Add a debug implementation for Address * fmt * Ensure debug works for messagechannel & show RC info * format * Add test * Remove refcounter type from struct name * Ensure debug works for messagechannel & show RC info * Fix rebase issue * Turbofish over type annotation (@thomaseizinger) Thanks to @thomaseizinger! Co-authored-by: Thomas Eizinger <[email protected]> * Remove unnecessary locking * rustfmt * Try fix MSRV issue * Revert (original change red herring) Technically this is not an MSRV issue, this is an actions + not commiting Cargo.lock issue, since having async_global_executor on 2021 should be fine as long as your compiler is also on 2021, and xtra won't specifically bring in the 2021 edition as it. Co-authored-by: Thomas Eizinger <[email protected]> * Minimal 2021 edition update, MSRV -> 1.56, GHA update (#80) * Minimal ed2021 update, and MSRV -> 1.56 * Set MSRV in Cargo.toml * Use minimal versions for all CI runs * typo * Update minimum dep for basic_wasm_bindgen console_error_panic_hook < 0.1.5 was nightly only. This change was needed to make CI with minimum versions pass. Really, it's a little unnecessary for an example to have an MSRV, but to make this CI work with the fewest modifications it's the easiest option. * Update to HEAD of flume fork * Sink for Handler<Return = ()> only * Add example showcasing usage of `Address` as `Sink` * Add example for sending on an interval based on stream * Add a debug implementation for Address (#67) * Add a debug implementation for Address * fmt * Ensure debug works for messagechannel & show RC info * format * Add test * Remove refcounter type from struct name * Ensure debug works for messagechannel & show RC info * Fix rebase issue * Turbofish over type annotation (@thomaseizinger) Thanks to @thomaseizinger! Co-authored-by: Thomas Eizinger <[email protected]> * Remove unnecessary locking * rustfmt * Try fix MSRV issue * Revert (original change red herring) Technically this is not an MSRV issue, this is an actions + not commiting Cargo.lock issue, since having async_global_executor on 2021 should be fine as long as your compiler is also on 2021, and xtra won't specifically bring in the 2021 edition as it. Co-authored-by: Thomas Eizinger <[email protected]> * Addresses are sinks POC (based on flume changes) * Fmt * update examples (Address is no longer Sync) * Fmt * 1.56 compliance (for CI) * Update flume to crates.io Co-authored-by: Thomas Eizinger <[email protected]>
- Loading branch information
1 parent
b7049c3
commit 3e624f5
Showing
10 changed files
with
169 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use futures_util::stream::repeat; | ||
use futures_util::StreamExt; | ||
use xtra::prelude::*; | ||
use xtra::spawn::Tokio; | ||
|
||
#[derive(Default)] | ||
struct Accumulator { | ||
sum: u32, | ||
} | ||
|
||
#[async_trait] | ||
impl Actor for Accumulator { | ||
type Stop = (); | ||
|
||
async fn stopped(self) -> Self::Stop {} | ||
} | ||
|
||
struct Add(u32); | ||
|
||
struct GetSum; | ||
|
||
#[async_trait] | ||
impl Handler<Add> for Accumulator { | ||
type Return = (); | ||
|
||
async fn handle(&mut self, Add(number): Add, _ctx: &mut Context<Self>) { | ||
self.sum += number; | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Handler<GetSum> for Accumulator { | ||
type Return = u32; | ||
|
||
async fn handle(&mut self, _: GetSum, _ctx: &mut Context<Self>) -> Self::Return { | ||
self.sum | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let addr = Accumulator::default() | ||
.create(None) | ||
.spawn(&mut Tokio::Global); | ||
|
||
repeat(10) | ||
.take(4) | ||
.map(|number| Ok(Add(number))) | ||
.forward(addr.clone()) | ||
.await | ||
.unwrap(); | ||
|
||
let sum = addr.send(GetSum).await.unwrap(); | ||
println!("Sum is {}!", sum); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use futures_core::Stream; | ||
use futures_util::stream::repeat; | ||
use futures_util::StreamExt; | ||
use std::time::Duration; | ||
use xtra::prelude::*; | ||
use xtra::spawn::Tokio; | ||
use xtra::Disconnected; | ||
|
||
#[derive(Default)] | ||
struct Greeter; | ||
|
||
#[async_trait] | ||
impl Actor for Greeter { | ||
type Stop = (); | ||
|
||
async fn stopped(self) -> Self::Stop {} | ||
} | ||
|
||
struct Greet; | ||
|
||
#[async_trait] | ||
impl Handler<Greet> for Greeter { | ||
type Return = (); | ||
|
||
async fn handle(&mut self, _: Greet, _ctx: &mut Context<Self>) { | ||
println!("Hello!"); | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let addr = Greeter::default().create(None).spawn(&mut Tokio::Global); | ||
|
||
greeter_stream(500).forward(addr).await.unwrap(); | ||
} | ||
|
||
fn greeter_stream(delay: u64) -> impl Stream<Item = Result<Greet, Disconnected>> { | ||
repeat(Duration::from_millis(delay)) | ||
.then(tokio::time::sleep) | ||
.map(|_| Ok(Greet)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.