From 0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 14 Oct 2014 19:38:38 +0200 Subject: adapt to new event package --- javascript/javascript_runtime.go | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'javascript/javascript_runtime.go') diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go index ffc672a63..16e22964f 100644 --- a/javascript/javascript_runtime.go +++ b/javascript/javascript_runtime.go @@ -11,9 +11,9 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpipe" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/event" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" ) @@ -25,9 +25,8 @@ type JSRE struct { Vm *otto.Otto pipe *ethpipe.JSPipe - blockChan chan ethreact.Event - changeChan chan ethreact.Event - quitChan chan bool + events event.Subscription + quitChan chan bool objectCb map[string][]otto.Value } @@ -51,8 +50,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { ethereum, otto.New(), ethpipe.NewJSPipe(ethereum), - make(chan ethreact.Event, 10), - make(chan ethreact.Event, 10), + nil, make(chan bool), make(map[string][]otto.Value), } @@ -68,8 +66,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { go re.mainLoop() // Subscribe to events - reactor := ethereum.Reactor() - reactor.Subscribe("newBlock", re.blockChan) + mux := ethereum.EventMux() + re.events = mux.Subscribe(ethchain.NewBlockEvent{}) re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum}) @@ -105,25 +103,16 @@ func (self *JSRE) Require(file string) error { } func (self *JSRE) Stop() { + self.events.Unsubscribe() // Kill the main loop self.quitChan <- true - close(self.blockChan) close(self.quitChan) - close(self.changeChan) jsrelogger.Infoln("stopped") } func (self *JSRE) mainLoop() { -out: - for { - select { - case <-self.quitChan: - break out - case block := <-self.blockChan: - if _, ok := block.Resource.(*ethchain.Block); ok { - } - } + for _ = range self.events.Chan() { } } @@ -201,13 +190,13 @@ func (self *JSRE) watch(call otto.FunctionCall) otto.Value { if storageCallback { self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb) - event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr)) - self.ethereum.Reactor().Subscribe(event, self.changeChan) + // event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr)) + // self.ethereum.EventMux().Subscribe(event, self.changeChan) } else { self.objectCb[addr] = append(self.objectCb[addr], cb) - event := "object:" + string(ethutil.Hex2Bytes(addr)) - self.ethereum.Reactor().Subscribe(event, self.changeChan) + // event := "object:" + string(ethutil.Hex2Bytes(addr)) + // self.ethereum.EventMux().Subscribe(event, self.changeChan) } return otto.UndefinedValue() -- cgit