Skip to content

Instantly share code, notes, and snippets.

@teivah
Created March 27, 2020 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teivah/41447aa566a95e496082f1ba08f241ab to your computer and use it in GitHub Desktop.
Save teivah/41447aa566a95e496082f1ba08f241ab to your computer and use it in GitHub Desktop.
ch := make(chan rxgo.Item)
go func() {
ch <- rxgo.Of(1)
ch <- rxgo.Of(2)
ch <- rxgo.Of(3)
close(ch)
}()
source := rxgo.FromChannel(ch, rxgo.WithPublishStrategy())
obs1 := source.Map(func(_ context.Context, i interface{}) (interface{}, error) {
return i.(int) + 1, nil
}).DoOnNext(func(i interface{}) {
fmt.Printf("%v\n", i)
})
obs2 := source.Map(func(_ context.Context, i interface{}) (interface{}, error) {
return i.(int) * 10, nil
}).DoOnNext(func(i interface{}) {
fmt.Printf("%v\n", i)
})
source.Connect()
<-obs1
<-obs2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment