Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Abuse scope more in one place, and much less everywhere else

  • Loading branch information...
commit e86d8066d815d569c3b6b9ccdeb6abe0f0da59f4 1 parent ac61b8d
Michael Bernstein authored

Showing 2 changed files with 13 additions and 13 deletions. Show diff stats Hide diff stats

  1. +9 9 examples/syncasync/main.go
  2. +4 4 node.go
18 examples/syncasync/main.go
@@ -27,7 +27,7 @@ func main() {
27 27
28 28 node.NewAsyncEvent(Starter)
29 29
30   - node.NewAsyncEvent(Watcher(node))
  30 + node.NewAsyncEvent(Watcher(node, graph))
31 31
32 32 node.NewAsyncEvent(ASyncLogger)
33 33 node.NewAsyncEvent(ASyncLogger)
@@ -45,7 +45,7 @@ func main() {
45 45 os.Exit(0)
46 46 }
47 47
48   -func Starter(c syl.Channels, g syl.ControlChan) {
  48 +func Starter(c syl.Channels) {
49 49 for {
50 50 for cd := 0; cd < 100; cd++ {
51 51 c.Data <- []byte{byte(cd)}
@@ -54,14 +54,14 @@ func Starter(c syl.Channels, g syl.ControlChan) {
54 54 c.Control.Exit()
55 55 }
56 56
57   -func Watcher(node *syl.Node) syl.Event {
58   - return func(c syl.Channels, g syl.ControlChan) {
  57 +func Watcher(node *syl.Node, graph *syl.Graph) syl.Event {
  58 + return func(c syl.Channels) {
59 59 for {
60 60 select {
61 61 case control := <-c.Control:
62 62 switch {
63 63 case bytes.Equal(control, syl.NodeExit()):
64   - g.Exit()
  64 + graph.Control.Exit()
65 65 case bytes.Equal(control, syl.NodeNext()):
66 66 node.NextSyncEvent()
67 67 default:
@@ -72,7 +72,7 @@ func Watcher(node *syl.Node) syl.Event {
72 72 }
73 73 }
74 74
75   -func ASyncLogger(c syl.Channels, g syl.ControlChan) {
  75 +func ASyncLogger(c syl.Channels) {
76 76 for {
77 77 select {
78 78 case data := <-c.Data:
@@ -82,7 +82,7 @@ func ASyncLogger(c syl.Channels, g syl.ControlChan) {
82 82 }
83 83 }
84 84
85   -func SyncLogger(c syl.Channels, g syl.ControlChan) {
  85 +func SyncLogger(c syl.Channels) {
86 86 select {
87 87 case data := <-c.Data:
88 88 <-time.After(time.Duration(rand.Int31n(10)) * time.Millisecond)
@@ -91,7 +91,7 @@ func SyncLogger(c syl.Channels, g syl.ControlChan) {
91 91 }
92 92 }
93 93
94   -func SyncLogger2(c syl.Channels, g syl.ControlChan) {
  94 +func SyncLogger2(c syl.Channels) {
95 95 select {
96 96 case data := <-c.Data:
97 97 <-time.After(time.Duration(rand.Int31n(10)) * time.Millisecond)
@@ -100,7 +100,7 @@ func SyncLogger2(c syl.Channels, g syl.ControlChan) {
100 100 }
101 101 }
102 102
103   -func SyncLogger3(c syl.Channels, g syl.ControlChan) {
  103 +func SyncLogger3(c syl.Channels) {
104 104 select {
105 105 case data := <-c.Data:
106 106 <-time.After(time.Duration(rand.Int31n(10)) * time.Millisecond)
8 node.go
... ... @@ -1,6 +1,6 @@
1 1 package sylvester
2 2
3   -type Event func(Channels, ControlChan)
  3 +type Event func(Channels)
4 4
5 5 type Node struct {
6 6 id []byte
@@ -56,12 +56,12 @@ func (n *Node) Activate() {
56 56
57 57 func (n *Node) StartAsyncEvents() {
58 58 for _, event := range n.asyncEvents {
59   - go event(*n.Channels, n.graph.Control)
  59 + go event(*n.Channels)
60 60 }
61 61 }
62 62
63 63 func (n *Node) StartSyncEvents() {
64   - go n.syncEvents[n.syncPosition](*n.Channels, n.graph.Control)
  64 + go n.syncEvents[n.syncPosition](*n.Channels)
65 65 }
66 66
67 67 func (n *Node) NextSyncEvent() {
@@ -71,5 +71,5 @@ func (n *Node) NextSyncEvent() {
71 71 } else {
72 72 n.syncPosition++
73 73 }
74   - go n.syncEvents[n.syncPosition](*n.Channels, n.graph.Control)
  74 + go n.syncEvents[n.syncPosition](*n.Channels)
75 75 }

0 comments on commit e86d806

Please sign in to comment.
Something went wrong with that request. Please try again.