Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Last active September 4, 2020 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choonkeat/774dabc621078298d53a4aa7905d75bf to your computer and use it in GitHub Desktop.
Save choonkeat/774dabc621078298d53a4aa7905d75bf to your computer and use it in GitHub Desktop.
type Model struct{}
type Cmd struct {}
type Msg struct {}
type Flags struct{}
// func initialize(flags Flags) (Model, Cmd)
// func update(msg Msg, model Model) (Model, Cmd)
func programLoop() {
var mutex sync.Mutex
var flags Flags
var messages = make(chan Msg, 0)
globalState, cmd := initialize(flags)
go execAndEmitMsg(cmd, messages)
for msg := range messages {
mutex.Lock()
newState, cmd := update(msg, globalState)
globalState = newState
mutex.Unlock()
go execAndEmitMsg(cmd, messages)
}
}
//
//
//
func execAndEmitMsg(cmd Cmd, messages chan<- Msg) {
switch cmd.kind {
case "Http.get":
resp, err := fetchText(cmd.data)
if err != nil {
messages <- Msg{name: cmd.msg, Err: err}
return
}
messages <- Msg{name: cmd.msg, Ok: resp}
}
}
// func fetchText(url string) (string, error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment