AuditTime

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: 5 Imported by: 0

README

AuditTime

AuditTime waits until the source emits and then starts a timer. When the timer expires, AuditTime will emit the last value received from the source during the time period when the timer was active.

Documentation

Overview

AuditTime waits until the source emits and then starts a timer. When the timer expires, AuditTime will emit the last value received from the source during the time period when the timer was active.

Example (AuditTime)
const ms = time.Millisecond

Interval(1 * ms).AuditTime(10 * ms).Take(5).Println()
Output:

9
19
29
39
49
Example (AuditTimeBursts)
const ms = time.Millisecond

burst20ms := func(i int) ObservableInt {
	return IntervalInt(5 * ms).Take(4).MapInt(func(j int) int {
		return i*100 + j
	})
}

fmt.Println("-1-")

IntervalInt(25 * ms).Take(4).MergeMapInt(burst20ms).AuditTime(21 * ms).Println()

fmt.Println("-2-")

IntervalInt(50 * ms).Take(4).MergeMapInt(burst20ms).AuditTime(14 * ms).Println()
Output:

-1-
3
103
203
-2-
2
3
102
103
202
203
302

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.

View Source
const TypecastFailed = RxError("typecast failed")

ErrTypecast is delivered to an observer if the generic value cannot be typecast to a specific type.

Variables

This section is empty.

Functions

This section is empty.

Types

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 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 Interval

func Interval(interval time.Duration) Observable

Interval creates an Observable that emits a sequence of integers spaced by a particular time interval. First integer is not emitted immediately, but only after the first time interval has passed. The generated code will do a type conversion from int to interface{}.

func (Observable) AsObservableInt

func (o Observable) AsObservableInt() ObservableInt

AsObservableInt turns an Observable of interface{} into an ObservableInt. If during observing a typecast fails, the error ErrTypecastToInt will be emitted.

func (Observable) AuditTime

func (o Observable) AuditTime(duration time.Duration) Observable

AuditTime waits until the source emits and then starts a timer. When the timer expires, AuditTime will emit the last value received from the source during the time period when the timer was active.

func (Observable) Println

func (o Observable) Println(a ...interface{}) error

Println subscribes to the Observable and prints every item to os.Stdout while it waits for completion or error. Returns either the error or nil when the Observable completed normally. Println uses a serial scheduler created with NewScheduler().

func (Observable) Take

func (o Observable) Take(n int) Observable

Take emits only the first n items emitted by an Observable.

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 IntervalInt

func IntervalInt(interval time.Duration) ObservableInt

IntervalInt creates an ObservableInt that emits a sequence of integers spaced by a particular time interval. First integer is not emitted immediately, but only after the first time interval has passed. The generated code will do a type conversion from int to int.

func (ObservableInt) AsObservable

func (o ObservableInt) AsObservable() Observable

AsObservable turns a typed ObservableInt into an Observable of interface{}.

func (ObservableInt) AuditTime

func (o ObservableInt) AuditTime(duration time.Duration) ObservableInt

AuditTime waits until the source emits and then starts a timer. When the timer expires, AuditTime will emit the last value received from the source during the time period when the timer was active.

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) MapInt

func (o ObservableInt) MapInt(project func(int) int) ObservableInt

MapInt transforms the items emitted by an ObservableInt by applying a function to each item.

func (ObservableInt) MapObservableInt

func (o ObservableInt) MapObservableInt(project func(int) ObservableInt) ObservableObservableInt

MapObservableInt transforms the items emitted by an ObservableInt by applying a function to each item.

func (ObservableInt) MergeMapInt

func (o ObservableInt) MergeMapInt(project func(int) ObservableInt) ObservableInt

MergeMapInt transforms the items emitted by an ObservableInt by applying a function to each item an returning an ObservableInt. The stream of ObservableInt items is then merged into a single stream of Int items using the MergeAll operator.

func (ObservableInt) Println

func (o ObservableInt) Println(a ...interface{}) error

Println subscribes to the Observable and prints every item to os.Stdout while it waits for completion or error. Returns either the error or nil when the Observable completed normally. Println uses a serial scheduler created with NewScheduler().

func (ObservableInt) Take

func (o ObservableInt) Take(n int) ObservableInt

Take emits only the first n items emitted by an ObservableInt.

type ObservableIntObserver

type ObservableIntObserver func(next ObservableInt, err error, done bool)

ObservableIntObserver 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 ObservableObservableInt

type ObservableObservableInt func(ObservableIntObserver, Scheduler, Subscriber)

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

func (ObservableObservableInt) AutoUnsubscribe

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 (ObservableObservableInt) MergeAll

MergeAll flattens a higher order observable by merging the observables it emits.

type Observer

type Observer func(next interface{}, err error, done bool)

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