observable_create
The create_observable provides a simple way to create custom observables by
defining a producer function that can emit values to subscribers.
The producer function is cloned for each subscribe call to avoid shared state between individual subscriptions.
See Also
- DeferredObservable - Subscribes to an observable returned by a function.
- JustObservable - Immediately emits a single value!
- EmptyObservable - Immediately completes!
- ThrowObservable - Immediately errors!
- ClosedObservable - Immediately unsubscribes!
- NeverObservable - Never emits, never unsubscribes! Only once dropped!
Example
cargo run -p rx_core --example observable_create_example
let _s = create_observable::<&str, Never, _>(|destination| {
destination.next("hello");
destination.complete();
})
.subscribe(PrintObserver::new("create_observable"));
create_observable - next: "hello"
create_observable - completed
create_observable - unsubscribed