mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
Move pubMsg to dispatch
This commit is contained in:
parent
cb222ceb22
commit
8d1497a408
3 changed files with 11 additions and 14 deletions
12
dispatch.go
12
dispatch.go
|
@ -6,6 +6,10 @@ import (
|
|||
"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.
|
||||
// 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.
|
||||
|
@ -53,9 +57,11 @@ func Pub(channel string, payload []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
var resChan = make(chan *BaseMsg, 10)
|
||||
var doneChan = make(chan bool)
|
||||
var wg sync.WaitGroup
|
||||
func PubMsg(channel string, msg *Msg) {
|
||||
payload, err := proto.Marshal(msg)
|
||||
check(err)
|
||||
Pub(channel, payload)
|
||||
}
|
||||
|
||||
func DispatchLoop() {
|
||||
wg.Add(1)
|
||||
|
|
5
main.go
5
main.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/ry/v8worker2"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -66,7 +65,7 @@ func main() {
|
|||
cwd, err := os.Getwd()
|
||||
check(err)
|
||||
|
||||
out, err := proto.Marshal(&Msg{
|
||||
PubMsg("start", &Msg{
|
||||
Payload: &Msg_Start{
|
||||
Start: &StartMsg{
|
||||
Cwd: &cwd,
|
||||
|
@ -77,8 +76,6 @@ func main() {
|
|||
},
|
||||
},
|
||||
})
|
||||
check(err)
|
||||
Pub("start", out)
|
||||
|
||||
DispatchLoop()
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (t *Timer) StartTimer() {
|
|||
if !t.Interval {
|
||||
t.Done = true
|
||||
}
|
||||
pubMsg(&Msg{
|
||||
PubMsg("timers", &Msg{
|
||||
Payload: &Msg_TimerReady{
|
||||
TimerReady: &TimerReadyMsg{
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue