1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

Move pubMsg to dispatch

This commit is contained in:
Ryan Dahl 2018-05-23 17:23:50 -04:00
parent cb222ceb22
commit 8d1497a408
3 changed files with 11 additions and 14 deletions

View file

@ -6,6 +6,10 @@ import (
"sync" "sync"
) )
var resChan = make(chan *BaseMsg, 10)
var doneChan = make(chan bool)
var wg sync.WaitGroup
// There is a single global worker for this process. // There is a single global worker for this process.
// This file should be the only part of deno that directly access it, so that // This file should be the only part of deno that directly access it, so that
// all interaction with V8 can go through a single point. // all interaction with V8 can go through a single point.
@ -53,9 +57,11 @@ func Pub(channel string, payload []byte) {
} }
} }
var resChan = make(chan *BaseMsg, 10) func PubMsg(channel string, msg *Msg) {
var doneChan = make(chan bool) payload, err := proto.Marshal(msg)
var wg sync.WaitGroup check(err)
Pub(channel, payload)
}
func DispatchLoop() { func DispatchLoop() {
wg.Add(1) wg.Add(1)

View file

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/golang/protobuf/proto"
"github.com/ry/v8worker2" "github.com/ry/v8worker2"
"io/ioutil" "io/ioutil"
"log" "log"
@ -66,7 +65,7 @@ func main() {
cwd, err := os.Getwd() cwd, err := os.Getwd()
check(err) check(err)
out, err := proto.Marshal(&Msg{ PubMsg("start", &Msg{
Payload: &Msg_Start{ Payload: &Msg_Start{
Start: &StartMsg{ Start: &StartMsg{
Cwd: &cwd, Cwd: &cwd,
@ -77,8 +76,6 @@ func main() {
}, },
}, },
}) })
check(err)
Pub("start", out)
DispatchLoop() DispatchLoop()
} }

View file

@ -61,7 +61,7 @@ func (t *Timer) StartTimer() {
if !t.Interval { if !t.Interval {
t.Done = true t.Done = true
} }
pubMsg(&Msg{ PubMsg("timers", &Msg{
Payload: &Msg_TimerReady{ Payload: &Msg_TimerReady{
TimerReady: &TimerReadyMsg{ TimerReady: &TimerReadyMsg{
Id: &t.Id, Id: &t.Id,
@ -75,9 +75,3 @@ func (t *Timer) StartTimer() {
} }
}() }()
} }
func pubMsg(msg *Msg) {
payload, err := proto.Marshal(msg)
check(err)
Pub("timers", payload)
}