[−][src]Struct mogwai::txrx::Transmitter
Send messages instantly.
Implementations
impl<A: 'static> Transmitter<A>
[src]
pub fn new() -> Transmitter<A>
[src]
Create a new transmitter.
pub fn spawn_recv(&self) -> Receiver<A>
[src]
Spawn a receiver for this transmitter.
pub fn send(&self, a: &A)
[src]
Send a message to any and all receivers of this transmitter.
pub fn send_many(&self, msgs: &[A])
[src]
Send a bunch of messages.
pub fn send_async<FutureA>(&self, fa: FutureA) where
FutureA: Future<Output = A> + 'static,
[src]
FutureA: Future<Output = A> + 'static,
Execute a future that results in a message, then send it. wasm32
spawns
a local execution context to drive the Future
to completion. Outside of
wasm32
(e.g. during server-side rendering) this is a noop.
Notes
Does not exist outside of the wasm32 architecture because the
functionality of wasm_bindgen_futures::spawn_local
is largely
managed by third party runtimes that mogwai does not need to depend
upon. If send_async
is necessary for server side rendering it may be
better to modify the behavior so the Future
resolves outside of the
Transmitter
lifecycle.
extern crate mogwai; extern crate web_sys; use mogwai::prelude::*; use web_sys::{Request, RequestMode, RequestInit, Response}; // Here's our async function that fetches a text response from a server, // or returns an error string. async fn request_to_text(req:Request) -> Result<String, String> { let resp:Response = JsFuture::from( window() .fetch_with_request(&req) ) .await .map_err(|_| "request failed".to_string())? .dyn_into() .map_err(|_| "response is malformed")?; let text:String = JsFuture::from( resp .text() .map_err(|_| "could not get response text")? ) .await .map_err(|_| "getting text failed")? .as_string() .ok_or("couldn't get text as string".to_string())?; Ok(text) } let (tx, rx) = txrx(); tx.send_async(async { let mut opts = RequestInit::new(); opts.method("GET"); opts.mode(RequestMode::Cors); let req = Request::new_with_str_and_init( "https://worldtimeapi.org/api/timezone/Europe/London.txt", &opts ) .unwrap_throw(); request_to_text(req) .await .unwrap_or_else(|e| e) });
pub fn contra_filter_fold_shared<B, T, F>(
&self,
var: Rc<RefCell<T>>,
f: F
) -> Transmitter<B> where
B: 'static,
T: 'static,
F: Fn(&mut T, &B) -> Option<A> + 'static,
[src]
&self,
var: Rc<RefCell<T>>,
f: F
) -> Transmitter<B> where
B: 'static,
T: 'static,
F: Fn(&mut T, &B) -> Option<A> + 'static,
Extend this transmitter with a new transmitter using a filtering fold
function. The given function folds messages of B
over a shared state T
and optionally sends A
s down into this transmitter.
pub fn contra_filter_fold<B, X, T, F>(&self, init: X, f: F) -> Transmitter<B> where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &B) -> Option<A> + 'static,
[src]
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &B) -> Option<A> + 'static,
Extend this transmitter with a new transmitter using a filtering fold
function. The given function folds messages of B
over a state T
and
optionally sends A
s into this transmitter.
pub fn contra_fold<B, X, T, F>(&self, init: X, f: F) -> Transmitter<B> where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &B) -> A + 'static,
[src]
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &B) -> A + 'static,
Extend this transmitter with a new transmitter using a fold function.
The given function folds messages of B
into a state T
and sends A
s
into this transmitter.
pub fn contra_filter_map<B, F>(&self, f: F) -> Transmitter<B> where
B: 'static,
F: Fn(&B) -> Option<A> + 'static,
[src]
B: 'static,
F: Fn(&B) -> Option<A> + 'static,
Extend this transmitter with a new transmitter using a filter function.
The given function maps messages of B
and optionally sends A
s into this
transmitter.
pub fn contra_map<B, F>(&self, f: F) -> Transmitter<B> where
B: 'static,
F: Fn(&B) -> A + 'static,
[src]
B: 'static,
F: Fn(&B) -> A + 'static,
Extend this transmitter with a new transmitter using a map function.
The given function maps messages of B
into A
s and sends them all into
this transmitter. This is much like Haskell's
contramap,
hence the contra_
prefix on this family of methods.
pub fn wire_filter_fold_shared<T, B, F>(
&self,
rb: &Receiver<B>,
var: Rc<RefCell<T>>,
f: F
) where
B: 'static,
T: 'static,
F: Fn(&mut T, &A) -> Option<B> + 'static,
[src]
&self,
rb: &Receiver<B>,
var: Rc<RefCell<T>>,
f: F
) where
B: 'static,
T: 'static,
F: Fn(&mut T, &A) -> Option<B> + 'static,
Wires the transmitter to send to the given receiver using a stateful fold function, where the state is a shared mutex.
The fold function returns an Option<B>
. In the case that the value of
Option<B>
is None
, no message will be sent to the receiver.
pub fn wire_filter_fold<T, B, X, F>(&self, rb: &Receiver<B>, init: X, f: F) where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> Option<B> + 'static,
[src]
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> Option<B> + 'static,
Wires the transmitter to send to the given receiver using a stateful fold function.
The fold function returns an Option<B>
. In the case that the value of
Option<B>
is None
, no message will be sent to the receiver.
pub fn wire_fold<T, B, X, F>(&self, rb: &Receiver<B>, init: X, f: F) where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> B + 'static,
[src]
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> B + 'static,
Wires the transmitter to send to the given receiver using a stateful fold function.
pub fn wire_fold_shared<T, B, F>(
&self,
rb: &Receiver<B>,
var: Rc<RefCell<T>>,
f: F
) where
B: 'static,
T: 'static,
F: Fn(&mut T, &A) -> B + 'static,
[src]
&self,
rb: &Receiver<B>,
var: Rc<RefCell<T>>,
f: F
) where
B: 'static,
T: 'static,
F: Fn(&mut T, &A) -> B + 'static,
Wires the transmitter to send to the given receiver using a stateful fold function, where the state is a shared mutex.
pub fn wire_filter_map<B, F>(&self, rb: &Receiver<B>, f: F) where
B: 'static,
F: Fn(&A) -> Option<B> + 'static,
[src]
B: 'static,
F: Fn(&A) -> Option<B> + 'static,
Wires the transmitter to the given receiver using a stateless map function.
If the map function returns None
for any messages those messages will
not be sent to the given transmitter.
pub fn wire_map<B, F>(&self, rb: &Receiver<B>, f: F) where
B: 'static,
F: Fn(&A) -> B + 'static,
[src]
B: 'static,
F: Fn(&A) -> B + 'static,
Wires the transmitter to the given receiver using a stateless map function.
pub fn wire_filter_fold_async<T, B, X, F, H>(
&self,
rb: &Receiver<B>,
init: X,
f: F,
h: H
) where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> Option<RecvFuture<B>> + 'static,
H: Fn(&mut T, &Option<B>) + 'static,
[src]
&self,
rb: &Receiver<B>,
init: X,
f: F,
h: H
) where
B: 'static,
T: 'static,
X: Into<T>,
F: Fn(&mut T, &A) -> Option<RecvFuture<B>> + 'static,
H: Fn(&mut T, &Option<B>) + 'static,
Wires the transmitter to the given receiver using a stateful fold function
that returns an optional future. The future, if available, results in an
Option<B>
. In the case that the value of the future's result is None
,
no message will be sent to the given receiver.
Lastly, a clean up function is ran at the completion of the future with its result.
To aid in returning a viable future in your fold function, use
wrap_future
.
Trait Implementations
impl<A> Clone for Transmitter<A>
[src]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl<A> !RefUnwindSafe for Transmitter<A>
impl<A> !Send for Transmitter<A>
impl<A> !Sync for Transmitter<A>
impl<A> Unpin for Transmitter<A>
impl<A> !UnwindSafe for Transmitter<A>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,