Giter Club home page Giter Club logo

tango's People

Contributors

le-vlad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tango's Issues

Modifying the message in a stage will result in panic

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 !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.