-
-
Save choonkeat/774dabc621078298d53a4aa7905d75bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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