github.com/MontFerret/ferret@v0.18.0/pkg/runtime/events/observable.go (about) 1 package events 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/runtime/core" 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 ) 9 10 type ( 11 // Subscription represents an event subscription object that contains target event name 12 // and optional event options. 13 Subscription struct { 14 EventName string 15 Options *values.Object 16 } 17 18 // Message represents an event message that an Observable can emit. 19 Message interface { 20 Value() core.Value 21 Err() error 22 } 23 24 // Stream represents an event stream that produces target event objects. 25 Stream interface { 26 Close(ctx context.Context) error 27 Read(ctx context.Context) <-chan Message 28 } 29 30 // Observable represents an interface of 31 // complex types that returns stream of events. 32 Observable interface { 33 Subscribe(ctx context.Context, subscription Subscription) (Stream, error) 34 } 35 )