flow

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package flow provides a Flow implementation to perform background processing and notify your subscribers through an Emitter.

Create a new instance of Flow, example:

flw := flow.New(func(emitter concurrent.Emitter) {
	// ...
	result, err := repository.Get(id)
	if err != nil {
		emitter.OnError(err)
		return
	}

	emitter.OnNext(result)
	emitter.OnComplete()
})

Subscribing to a Flow (Safe Concurrency), example:

flw.SubscribeOutboxEvent(
	func(data interface) {
		// OnNext
		// ...
	},
	func(err error) {
		// OnError
		// ...
	},
	func(ok bool) {
		// OnComplete
		if ok {
			// ...
	})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

type Emitter struct {
	// contains filtered or unexported fields
}

Emitter push signals to subscriber.

func (Emitter) OnComplete

func (e Emitter) OnComplete()

OnComplete send the completed signal to subscriber.

func (Emitter) OnError

func (e Emitter) OnError(err error)

OnError send errors signals to subscriber.

func (Emitter) OnNext

func (e Emitter) OnNext(data interface{})

OnNext send data signals to subscriber.

type Flow

type Flow struct {
	// contains filtered or unexported fields
}

Flow performs background processing and notifies your subscribers via an Emitter.

func New

func New(onSubscribe func(emitter Emitter)) *Flow

New create new instance of Flow.

func (*Flow) Subscribe

func (f *Flow) Subscribe(onNext func(data interface{}), onError func(err error), onComplete func(ok bool))

SubscribeOutboxEvent records callbacks for onNext, onError and onComplete. When subscribing to a Flow, processing is performed in the background and callbacks are notified via signals. Safe Concurrency.

func (*Flow) SubscribeOnComplete

func (f *Flow) SubscribeOnComplete(onComplete func(ok bool))

SubscribeOnComplete registers callbacks for onComplete. When subscribing to a Flow, processing is performed in the background and callbacks are notified via signals.

func (*Flow) SubscribeOnError

func (f *Flow) SubscribeOnError(onError func(err error))

SubscribeOnError registers callbacks for onError. When subscribing to a Flow, processing is performed in the background and callbacks are notified via signals.

func (*Flow) SubscribeOnNext

func (f *Flow) SubscribeOnNext(onNext func(data interface{}))

SubscribeOnNext registers callbacks for onNext. When subscribing to a Flow, processing is performed in the background and callbacks are notified via signals.

Jump to

Keyboard shortcuts

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