|
242 | 242 | io-id (zipmap (concat (vals ins) (vals outs)) (concat (keys ins) (keys outs))) |
243 | 243 | control (::flow/control ins) |
244 | 244 | ;;TODO rotate/randomize after control per normal alts? |
245 | | - read-chans (into [control] (-> ins (dissoc ::flow/control) vals)) |
| 245 | + read-chans (vec (-> ins (dissoc ::flow/control) vals)) |
246 | 246 | run |
247 | | - #(loop [status :paused, state state, count 0] |
| 247 | + #(loop [status :paused, state state, count 0, read-chans read-chans] |
248 | 248 | (let [pong (fn [] |
249 | 249 | (let [pins (dissoc ins ::flow/control) |
250 | 250 | pouts (dissoc outs ::flow/error ::flow/report)] |
|
254 | 254 | :ins (zipmap (keys pins) (map chan->data (vals pins))) |
255 | 255 | :outs (zipmap (keys pouts) (map chan->data (vals pouts)))}))) |
256 | 256 | handle-command (partial handle-command pid pong) |
257 | | - [nstatus nstate count] |
| 257 | + [nstatus nstate count read-chans] |
258 | 258 | (try |
259 | 259 | (if (= status :paused) |
260 | 260 | (let [nstatus (handle-command status (async/<!! control)) |
261 | 261 | nstate (handle-transition transition status nstatus state)] |
262 | | - [nstatus nstate count]) |
| 262 | + [nstatus nstate count read-chans]) |
263 | 263 | ;;:running |
264 | | - (let [[msg c] (async/alts!! read-chans :priority true) |
| 264 | + (let [[msg c] (async/alts!! (into [control] read-chans) :priority true) |
265 | 265 | cid (io-id c)] |
266 | 266 | (if (= c control) |
267 | 267 | (let [nstatus (handle-command status msg) |
268 | 268 | nstate (handle-transition transition status nstatus state)] |
269 | | - [nstatus nstate count]) |
| 269 | + [nstatus nstate count read-chans]) |
270 | 270 | (try |
271 | 271 | (let [[nstate outputs] (transform state cid msg) |
272 | 272 | [nstatus nstate] |
273 | 273 | (send-outputs status nstate outputs outs |
274 | 274 | resolver control handle-command transition)] |
275 | | - [nstatus nstate (inc count)]) |
| 275 | + [nstatus nstate (inc count) (if (some? msg) |
| 276 | + read-chans |
| 277 | + (vec (remove #{c} read-chans)))]) |
276 | 278 | (catch Throwable ex |
277 | 279 | (async/>!! (outs ::flow/error) |
278 | 280 | #::flow{:pid pid, :status status, :state state, |
279 | 281 | :count (inc count), :cid cid, :msg msg :op :step, :ex ex}) |
280 | | - [status state count]))))) |
| 282 | + [status state count read-chans]))))) |
281 | 283 | (catch Throwable ex |
282 | 284 | (async/>!! (outs ::flow/error) |
283 | | - #::flow{:pid pid, :status status, :state state, :count (inc count), :ex ex}) |
284 | | - [status state count]))] |
| 285 | + #::flow{:pid pid, :status status, :state state, :count (inc count), :ex ex}) |
| 286 | + [status state count read-chans]))] |
285 | 287 | (when-not (= nstatus :exit) ;;fall out |
286 | | - (recur nstatus nstate (long count)))))] |
| 288 | + (recur nstatus nstate (long count) read-chans))))] |
287 | 289 | ((futurize run {:exec exs}))))))) |
0 commit comments