Documentation
¶
Overview ¶
Never creates an Observable that emits no items and does't terminate.
It does not schedule a task and as such you won't be able to use a subscriber's Wait method for it to terminate if you use the operator by itself. Combine Never with e.g. Timeout to make it usefull.
Never http://reactivex.io/documentation/operators/empty-never-throw.html
Example (Never) ¶
concurrent := GoroutineScheduler()
source := Never().Timeout(time.Hour).SubscribeOn(concurrent)
never := true
subscription := source.Subscribe(func(next interface{}, err error, done bool) {
never = false
})
go func() {
time.Sleep(100 * time.Millisecond)
subscription.Unsubscribe()
}()
if subscription.Canceled() {
fmt.Println("expected subscription to be active!")
}
subscription.Wait()
if subscription.Subscribed() {
fmt.Println("expected subscription to be canceled!")
}
if never && subscription.Canceled() {
fmt.Println("OK")
}
Output: OK
Index ¶
Examples ¶
Constants ¶
const ErrUnsubscribed = RxError("subscriber unsubscribed")
Unsubscribed is the error returned by wait when the Unsubscribe method is called on the subscription.
const TimeoutOccured = RxError("timeout occured")
TimeoutOccured is delivered to an observer if the stream times out.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Observable ¶
type Observable func(Observer, Scheduler, Subscriber)
Observable is a function taking an Observer, Scheduler and Subscriber. Calling it will subscribe the Observer to events from the Observable.
func Never ¶
func Never() Observable
Never creates an Observable that emits no items and does't terminate.
func (Observable) Serialize ¶
func (o Observable) Serialize() Observable
Serialize forces an Observable to make serialized calls and to be well-behaved.
func (Observable) Subscribe ¶
func (o Observable) Subscribe(observe Observer, schedulers ...Scheduler) Subscription
Subscribe operates upon the emissions and notifications from an Observable. This method returns a Subscription. Subscribe uses a serial scheduler created with NewScheduler().
func (Observable) SubscribeOn ¶
func (o Observable) SubscribeOn(scheduler Scheduler) Observable
SubscribeOn specifies the scheduler an Observable should use when it is subscribed to.
func (Observable) Timeout ¶
func (o Observable) Timeout(due time.Duration) Observable
Timeout mirrors the source Observable, but issues an error notification if a particular period of time elapses without any emitted items. Timeout schedules a task on the scheduler passed to it during subscription.
type Observer ¶
Observer is a function that gets called whenever the Observable has something to report. The next argument is the item value that is only valid when the done argument is false. When done is true and the err argument is not nil, then the Observable has terminated with an error. When done is true and the err argument is nil, then the Observable has completed normally.
type Scheduler ¶
Scheduler is used to schedule tasks to support subscribing and observing.
func GoroutineScheduler ¶
func GoroutineScheduler() Scheduler
func NewScheduler ¶ added in v0.0.1
func NewScheduler() Scheduler
type Subscriber ¶
type Subscriber interface {
// A Subscriber is also a Subscription.
Subscription
// Add will create and return a new child Subscriber setup in such a way that
// calling Unsubscribe on the parent will also call Unsubscribe on the child.
// Calling the Unsubscribe method on the child will NOT propagate to the
// parent!
Add() Subscriber
// OnUnsubscribe will add the given callback function to the subscriber.
// The callback will be called when either the Unsubscribe of the parent
// or of the subscriber itself is called. If the subscription was already
// canceled, then the callback function will just be called immediately.
OnUnsubscribe(callback func())
// OnWait will register a callback to call when subscription Wait is called.
OnWait(callback func())
// Done will set the error internally and then cancel the subscription by
// calling the Unsubscribe method. A nil value for error indicates success.
Done(err error)
// Error returns the error set by calling the Done(err) method. As long as
// the subscriber is still subscribed Error will return nil.
Error() error
}
Subscriber is a Subscription with management functionality.
func NewSubscriber ¶ added in v0.0.1
func NewSubscriber() Subscriber
New will create and return a new Subscriber.
type Subscription ¶
type Subscription interface {
// Subscribed returns true when the subscription is currently active.
Subscribed() bool
// Unsubscribe will do nothing if the subscription is not active. If the
// state is still active however, it will be changed to canceled.
// Subsequently, it will call Unsubscribe on all child subscriptions added
// through Add, along with all methods added through OnUnsubscribe. When the
// subscription is canceled by calling Unsubscribe a call to the Wait method
// will return the error ErrUnsubscribed.
Unsubscribe()
// Canceled returns true when the subscription state is canceled.
Canceled() bool
// Wait will by default block the calling goroutine and wait for the
// Unsubscribe method to be called on this subscription.
// However, when OnWait was called with a callback wait function it will
// call that instead. Calling Wait on a subscription that has already been
// canceled will return immediately. If the subscriber was canceled by
// calling Unsubscribe, then the error returned is ErrUnsubscribed.
// If the subscriber was terminated by calling Done, then the error
// returned here is the one passed to Done.
Wait() error
}
Subscription is an interface that allows code to monitor and control a subscription it received.