usedatabrew / tango Goto Github PK
View Code? Open in Web Editor NEWOpen Source pipeline lib with backpressure
Home Page: https://databrew.tech
License: MIT License
Open Source pipeline lib with backpressure
Home Page: https://databrew.tech
License: MIT License
Hello and thank you for your contribution to the community !
I have probably misunderstood how it is supposed to work - modifying the message will immediately result in panic.
What am I doing wrong ?
Here is my modification of the sample code:
package main
import (
"fmt"
"time"
"github.com/usedatabrew/tango"
)
func main() {
instance := tango.NewTango()
stages := []tango.Stage{
{
Channel: make(chan interface{}),
Function: func(msg interface{}) (interface{}, error) {
return fmt.Sprintf("%v stage 1", msg), nil
},
},
{
Channel: make(chan interface{}),
Function: func(msg interface{}) (interface{}, error) {
if msg.(int)%5 == 0 {
time.Sleep(time.Millisecond * 10)
}
return fmt.Sprintf("%v stage 2", msg), nil
},
},
{
Channel: make(chan interface{}),
Function: func(msg interface{}) (interface{}, error) {
return fmt.Sprintf("%v stage 3", msg), nil
},
},
}
instance.SetStages(stages)
instance.OnProcessed(func(i interface{}, err error) {
if err != nil {
_ = fmt.Errorf("messages happened in the last stage %v", err)
}
fmt.Println("Message processed", i)
})
producerChannel := make(chan interface{})
go func() {
for i := 0; i <= 10000000; i++ {
producerChannel <- fmt.Sprintf("item %v", i)
time.Sleep(time.Millisecond * 200)
}
}()
// Tango will consume messages from the producer channel and
// pass them through the stages.
instance.SetProducerChannel(producerChannel)
if err := instance.Start(); err != nil {
panic(err)
}
}
Running this code will panic:
$ go run main.go
panic: interface conversion: interface {} is string, not int
goroutine 35 [running]:
main.main.func2({0x4ffce0?, 0xc000194010?})
/home/user/go/src/testTango/main.go:23 +0xcd
github.com/usedatabrew/tango.(*Tango).Start.func1(0x1)
/home/user/go/pkg/mod/cache/github.com/usedatabrew/[email protected]/tango.go:86 +0x171
created by github.com/usedatabrew/tango.(*Tango).Start in goroutine 1
/home/user/go/pkg/mod/cache/github.com/usedatabrew/[email protected]/tango.go:75 +0x125
exit status 2
Thanks for your enlightening !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.