Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manipulate a network in running #73

Open
brucekim opened this issue Jun 22, 2021 · 0 comments
Open

Manipulate a network in running #73

brucekim opened this issue Jun 22, 2021 · 0 comments

Comments

@brucekim
Copy link

brucekim commented Jun 22, 2021

@trustmaster

Hello, I would like to know how to dynamically manipulate a network in running.

I tested with a simple code below. However inserting a new process into the network already initialized doesn't change after the network running.
I am not sure whether this is a nature of design for flow based programming.

In addition, I would like to hear whether implementing such dynamic manipulating a network is meaningful or not.

type SrcTest struct {
	Out chan<- byte
}

type FilterTest1 struct {
	In <-chan byte
	Out chan<- byte
}

type FilterTest2 struct {
	In <-chan byte
	Out chan<- byte
}

type SinkTest struct {
	In <-chan byte
}

func (s *SrcTest) Process() {
	for {
		s.Out <- 'a'
		time.Sleep(100 * time.Millisecond)
	}
}

func (f *FilterTest1) Process() {
	for in := range f.In {
		_ = in
		f.Out <- 'b'
	}
}

func (f *FilterTest2) Process() {
	for in := range f.In {
		_ = in
		log.Infof("f2 f2")
		f.Out <- 'c'
	}
}

func (s *SinkTest) Process() {
	for in := range s.In {
		log.Infof("recv: %c", in)
	}
}

func TestStreamData(t *testing.T) {
	n := goflow.NewGraph()
	n.Add("src", new(SrcTest))
	n.Add("f1", new(FilterTest1))
	n.Add("sink", new(SinkTest))
	n.Connect("src", "Out", "f1", "In")
	n.Connect("f1", "Out", "sink", "In")

	wait := goflow.Run(n)
	go func() {
		time.Sleep(2 * time.Second)
		log.Infof("insert f2")


		n.Add("f2", new(FilterTest2))
		//n.Connect("f1", "Out", "f2", "In")
		n.Connect("src", "Out", "f2", "In")
		n.Connect("f2", "Out", "sink", "In")

	}()

	<-wait
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant