summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-05-21 22:07:40 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-05-21 22:07:40 -0400
commit08307fb84160602da12ba4d1b118c859e8a73cdb (patch)
treeb8f3bf7c4df3904937afc964ae36803567e78719 /main.go
parent9a6621659937c55c6005a1fa6ce9641a4ceff385 (diff)
Add dispatch pub/sub
Diffstat (limited to 'main.go')
-rw-r--r--main.go35
1 files changed, 4 insertions, 31 deletions
diff --git a/main.go b/main.go
index 9b4b6c120..409a7940d 100644
--- a/main.go
+++ b/main.go
@@ -8,7 +8,6 @@ import (
"net/url"
"os"
"path"
- "sync"
)
var flagReload = flag.Bool("reload", false, "Reload cached remote source code.")
@@ -19,9 +18,6 @@ var DenoDir string
var CompileDir string
var SrcDir string
-var wg sync.WaitGroup
-var resChan chan *Msg
-
func ResolveModule(moduleSpecifier string, containingFile string) (
moduleName string, filename string, err error) {
moduleUrl, err := url.Parse(moduleSpecifier)
@@ -58,7 +54,8 @@ func main() {
args = v8worker2.SetFlags(args)
createDirs()
- worker := v8worker2.New(recv)
+ createWorker()
+ InitHandlers()
main_js := stringAsset("main.js")
check(worker.Load("/main.js", main_js))
@@ -67,9 +64,6 @@ func main() {
cwd, err := os.Getwd()
check(err)
- resChan = make(chan *Msg)
- doneChan := make(chan bool)
-
out, err := proto.Marshal(&Msg{
Payload: &Msg_Start{
Start: &StartMsg{
@@ -82,28 +76,7 @@ func main() {
},
})
check(err)
- err = worker.SendBytes(out)
- if err != nil {
- os.Stderr.WriteString(err.Error())
- os.Exit(1)
- }
-
- // In a goroutine, we wait on for all goroutines to complete (for example
- // timers). We use this to signal to the main thread to exit.
- go func() {
- wg.Wait()
- doneChan <- true
- }()
+ Pub("start", out)
- for {
- select {
- case msg := <-resChan:
- out, err := proto.Marshal(msg)
- err = worker.SendBytes(out)
- check(err)
- case <-doneChan:
- // All goroutines have completed. Now we can exit main().
- return
- }
- }
+ DispatchLoop()
}