github.com/grahambrereton-form3/tilt@v0.10.18/internal/engine/README.md (about) 1 # Engine Design Doc 2 Engine is primarily a `for` loop that takes inputs from a variety of sources, updates state, and makes a decision based off of that state. The rough shape of the for loop is as follows: 3 4 ```go 5 state := &state{} 6 for { 7 select { 8 // sources like local filesystem, kubernetes, ui, etc 9 case ev := <- fsCh: 10 e.handleFsEvent(ev) 11 case ev := <- k8sCh: 12 e.handleK8sEvent(ev) 13 } 14 // decide what to do: start a pipeline, stop a pipeline 15 actions := handle(state) 16 // tell subscribers what we took 17 updateSubscribers(actions, state.copy()) 18 } 19 ``` 20 21 When state changes, and only when state changes, can we make decisions about what to do. Only after actions have been taken do we tell subscribers. 22 23 ## Rules 24 * No blocking I/O in the for loop 25 * No long operations in the for loop 26 * Actions taken in `handle` shouldn’t directly send to channels that this `for` `select`s on.