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.
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
Flow performs background processing and notifies your subscribers via an Emitter.
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 ¶
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 ¶
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.