github.com/alkemics/goflow@v0.2.1/wrappers/ifs/graph/ifs.go (about) 1 // Code generated by goflow DO NOT EDIT. 2 3 //go:build !codeanalysis 4 // +build !codeanalysis 5 6 package main 7 8 import ( 9 "github.com/alkemics/goflow/example/constants/numbers" 10 "github.com/alkemics/goflow/example/nodes" 11 ) 12 13 /* 14 15 */ 16 type Ifs struct{} 17 18 func NewIfs() Ifs { 19 return Ifs{} 20 } 21 22 func newIfs(id string) Ifs { 23 return Ifs{} 24 } 25 26 /* 27 28 */ 29 func (g *Ifs) Run() { 30 31 // __print_again_values outputs 32 var __print_again_values_aggregated []interface{} 33 34 // __print_values outputs 35 var __print_values_aggregated []interface{} 36 37 // __print_void_again_values outputs 38 var __print_void_again_values_aggregated []interface{} 39 40 // __print_void_values outputs 41 var __print_void_values_aggregated []interface{} 42 43 // print outputs 44 45 // print_again outputs 46 47 // print_void outputs 48 49 // print_void_again outputs 50 51 igniteNodeID := "ignite" 52 doneNodeID := "done" 53 54 done := make(chan string) 55 defer close(done) 56 57 steps := map[string]struct { 58 deps map[string]struct{} 59 run func() 60 alreadyDone bool 61 }{ 62 63 "__print_again_values": { 64 deps: map[string]struct{}{ 65 igniteNodeID: {}, 66 }, 67 run: func() { 68 __print_again_values_aggregated = append(__print_again_values_aggregated, "this is printed as well") 69 done <- "__print_again_values" 70 }, 71 alreadyDone: false, 72 }, 73 "__print_values": { 74 deps: map[string]struct{}{ 75 igniteNodeID: {}, 76 }, 77 run: func() { 78 __print_values_aggregated = append(__print_values_aggregated, "this is printed") 79 done <- "__print_values" 80 }, 81 alreadyDone: false, 82 }, 83 "__print_void_again_values": { 84 deps: map[string]struct{}{ 85 igniteNodeID: {}, 86 }, 87 run: func() { 88 __print_void_again_values_aggregated = append(__print_void_again_values_aggregated, "never printed as well") 89 done <- "__print_void_again_values" 90 }, 91 alreadyDone: false, 92 }, 93 "__print_void_values": { 94 deps: map[string]struct{}{ 95 igniteNodeID: {}, 96 }, 97 run: func() { 98 __print_void_values_aggregated = append(__print_void_values_aggregated, "never printed") 99 done <- "__print_void_values" 100 }, 101 alreadyDone: false, 102 }, 103 "print": { 104 deps: map[string]struct{}{ 105 "__print_values": {}, 106 igniteNodeID: {}, 107 }, 108 run: func() { 109 nodes.Printer(__print_values_aggregated) 110 done <- "print" 111 }, 112 alreadyDone: false, 113 }, 114 "print_again": { 115 deps: map[string]struct{}{ 116 "__print_again_values": {}, 117 igniteNodeID: {}, 118 }, 119 run: func() { 120 if len(numbers.EmptyIntSlice) == 0 { 121 nodes.Printer(__print_again_values_aggregated) 122 } 123 124 done <- "print_again" 125 }, 126 alreadyDone: false, 127 }, 128 "print_void": { 129 deps: map[string]struct{}{ 130 "__print_void_values": {}, 131 igniteNodeID: {}, 132 }, 133 run: func() { 134 if false { 135 nodes.Printer(__print_void_values_aggregated) 136 } 137 138 done <- "print_void" 139 }, 140 alreadyDone: false, 141 }, 142 "print_void_again": { 143 deps: map[string]struct{}{ 144 "__print_void_again_values": {}, 145 igniteNodeID: {}, 146 }, 147 run: func() { 148 if len(numbers.EmptyIntSlice) > 0 { 149 nodes.Printer(__print_void_again_values_aggregated) 150 } 151 152 done <- "print_void_again" 153 }, 154 alreadyDone: false, 155 }, 156 igniteNodeID: { 157 deps: map[string]struct{}{}, 158 run: func() { 159 done <- igniteNodeID 160 }, 161 alreadyDone: false, 162 }, 163 doneNodeID: { 164 deps: map[string]struct{}{ 165 "__print_again_values": {}, 166 "__print_values": {}, 167 "__print_void_again_values": {}, 168 "__print_void_values": {}, 169 "print": {}, 170 "print_again": {}, 171 "print_void": {}, 172 "print_void_again": {}, 173 }, 174 run: func() { 175 done <- doneNodeID 176 }, 177 alreadyDone: false, 178 }, 179 } 180 181 // Ignite 182 ignite := steps[igniteNodeID] 183 ignite.alreadyDone = true 184 steps[igniteNodeID] = ignite 185 go steps[igniteNodeID].run() 186 187 // Resolve the graph 188 for resolved := range done { 189 if resolved == doneNodeID { 190 // If all the graph was resolved, get out of the loop 191 break 192 } 193 194 for name, step := range steps { 195 delete(step.deps, resolved) 196 if len(step.deps) == 0 && !step.alreadyDone { 197 step.alreadyDone = true 198 steps[name] = step 199 go step.run() 200 } 201 } 202 } 203 204 return 205 }