Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge syncasync work

  • Loading branch information...
commit c7e34ff426ccb0818458104431c40075586339fd 2 parents c72cf3b + 23241ce
@mrb authored
View
BIN  examples/syncasync/syncasync
Binary file not shown
View
1  graph.go
@@ -18,6 +18,7 @@ func (g *Graph) Activate() {
for _, node := range g.nodemap {
go node.Activate()
}
+
for _, edge := range g.edges {
go edge.Activate(*g.Channels)
}
View
32 node.go
@@ -1,6 +1,8 @@
package sylvester
-import ()
+import (
+ "bytes"
+)
type Event func(Channels)
@@ -49,14 +51,32 @@ func (n *Node) NewSyncEvent(newEvent Event) error {
func (n *Node) Activate() {
if len(n.asyncEvents) > 0 {
- for _, event := range n.asyncEvents {
- go event(*n.Channels)
- }
+ n.StartAsyncEvents()
}
if len(n.syncEvents) > 0 {
- for _, event := range n.syncEvents {
- event(*n.Channels)
+ n.StartSyncEvents()
+ }
+}
+
+func (n *Node) StartAsyncEvents() {
+ for _, event := range n.asyncEvents {
+ go event(*n.Channels)
+ }
+}
+
+func (n *Node) StartSyncEvents() {
+ for _, event := range n.syncEvents {
+ go event(*n.Channels)
+ select {
+ case control := <-n.Control:
+ if bytes.Equal(control, NodeNext()) {
+
+ } else if bytes.Equal(control, NodeSyncEventRestart()) {
+ n.StartSyncEvents()
+ } else {
+ n.Control <- control
+ }
}
}
}
View
14 protocol.go
@@ -6,6 +6,8 @@ var (
"EXIT": {0, 1},
"PING": {0, 2},
"PONG": {0, 3},
+ "NEXT": {0, 4},
+ "SYNCRESTART": {0, 5},
}
)
@@ -26,6 +28,14 @@ func NodePong() []byte {
return Messages["PONG"]
}
+func NodeNext() []byte {
+ return Messages["NEXT"]
+}
+
+func NodeSyncEventRestart() []byte {
+ return Messages["SYNCRESTART"]
+}
+
// Functions for Channels
func (p ControlChan) Start() {
p <- Messages["START"]
@@ -42,3 +52,7 @@ func (p ControlChan) Ping() {
func (p ControlChan) Pong() {
p <- Messages["PONG"]
}
+
+func (p ControlChan) Next() {
+ p <- Messages["NEXT"]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.