MergeDelayError

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 3 Imported by: 0

README

MergeDelayError

MergeDelayError combines multiple Observables into one by merging their emissions. Any error will be deferred until all observables terminate.

MergeDelayError

Example

import _ "github.com/reactivego/rx/generic"

Code:

const _5ms = 5 * time.Millisecond
const _10ms = 10 * time.Millisecond

sourceA := CreateInt(func(N NextInt, E Error, _ Complete, _ Canceled) {
	N(1)
	E(RxError("error.sourceA"))
})

sourceB := CreateInt(func(N NextInt, _ Error, C Complete, _ Canceled) {
	time.Sleep(_5ms)
	N(0)
	time.Sleep(_10ms)
	N(2)
	C()
})

result, err := MergeDelayErrorInt(sourceA, sourceB).ToSlice()
fmt.Println(result, err)

Output:

[1 0 2] error.sourceA

Documentation

Overview

MergeDelayError combines multiple Observables into one by merging their emissions. Any error will be deferred until all observables terminate.

Example (MergeDelayError)
const _5ms = 5 * time.Millisecond
const _10ms = 10 * time.Millisecond

sourceA := CreateInt(func(N NextInt, E Error, _ Complete, _ Canceled) {
	N(1)
	E(RxError("error.sourceA"))
})

sourceB := CreateInt(func(N NextInt, _ Error, C Complete, _ Canceled) {
	time.Sleep(_5ms)
	N(0)
	time.Sleep(_10ms)
	N(2)
	C()
})

result, err := MergeDelayErrorInt(sourceA, sourceB).ToSlice()
fmt.Println(result, err)
Output:

[1 0 2] error.sourceA

Index

Examples

Constants

View Source
const ErrUnsubscribed = RxError("subscriber unsubscribed")

Unsubscribed is the error returned by wait when the Unsubscribe method is called on the subscription.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canceled

type Canceled func() bool

Canceled returns true when the observer has unsubscribed.

type Complete

type Complete func()

Complete signals that no more data is to be expected.

type Error

type Error func(error)

Error signals an error condition.

type IntObserver

type IntObserver func(next int, err error, done bool)

IntObserver 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 NextInt

type NextInt func(int)

NextInt can be called to emit the next value to the IntObserver.

type ObservableInt

type ObservableInt func(IntObserver, Scheduler, Subscriber)

ObservableInt is a function taking an Observer, Scheduler and Subscriber. Calling it will subscribe the Observer to events from the Observable.

func CreateInt

func CreateInt(create func(NextInt, Error, Complete, Canceled)) ObservableInt

CreateInt provides a way of creating an ObservableInt from scratch by calling observer methods programmatically.

The create function provided to CreateInt will be called once to implement the observable. It is provided with a NextInt, Error, Complete and Canceled function that can be called by the code that implements the Observable.

func EmptyInt

func EmptyInt() ObservableInt

EmptyInt creates an Observable that emits no items but terminates normally.

func MergeDelayErrorInt

func MergeDelayErrorInt(observables ...ObservableInt) ObservableInt

MergeDelayErrorInt combines multiple Observables into one by merging their emissions. Any error will be deferred until all observables terminate.

func (ObservableInt) AutoUnsubscribe

func (o ObservableInt) AutoUnsubscribe() ObservableInt

AutoUnsubscribe will automatically unsubscribe from the source when it signals it is done. This Operator subscribes to the source Observable using a separate subscriber. When the source observable subsequently signals it is done, the separate subscriber will be Unsubscribed.

func (ObservableInt) MergeDelayErrorWith

func (o ObservableInt) MergeDelayErrorWith(other ...ObservableInt) ObservableInt

MergeDelayError combines multiple Observables into one by merging their emissions. Any error will be deferred until all observables terminate.

func (ObservableInt) ToSlice

func (o ObservableInt) ToSlice() (slice []int, err error)

ToSlice collects all values from the ObservableInt into an slice. The complete slice and any error are returned. ToSlice uses a serial scheduler created with NewScheduler().

type RxError

type RxError string

func (RxError) Error

func (e RxError) Error() string

type Scheduler

type Scheduler = scheduler.Scheduler

Scheduler is used to schedule tasks to support subscribing and observing.

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 added in v0.0.1

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL