aboutsummaryrefslogtreecommitdiffstats
path: root/ethreact
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-07-15 01:50:06 +0800
committerzelig <viktor.tron@gmail.com>2014-07-15 01:50:06 +0800
commit3d5db7288f134fef7e51b25776007705f6663654 (patch)
treeedda6e8fd23584327473058411df9cd2c53241f4 /ethreact
parentdc11b5c55e2888a7a3dac51fedc3864d112136ce (diff)
parent8845fb7eae3e51fd3e55c47c377bf1a9e0cfe2a9 (diff)
downloaddexon-3d5db7288f134fef7e51b25776007705f6663654.tar
dexon-3d5db7288f134fef7e51b25776007705f6663654.tar.gz
dexon-3d5db7288f134fef7e51b25776007705f6663654.tar.bz2
dexon-3d5db7288f134fef7e51b25776007705f6663654.tar.lz
dexon-3d5db7288f134fef7e51b25776007705f6663654.tar.xz
dexon-3d5db7288f134fef7e51b25776007705f6663654.tar.zst
dexon-3d5db7288f134fef7e51b25776007705f6663654.zip
merge upstream
Diffstat (limited to 'ethreact')
-rw-r--r--ethreact/README.md40
-rw-r--r--ethreact/reactor_test.go63
2 files changed, 0 insertions, 103 deletions
diff --git a/ethreact/README.md b/ethreact/README.md
deleted file mode 100644
index 592b50b96..000000000
--- a/ethreact/README.md
+++ /dev/null
@@ -1,40 +0,0 @@
-# ethreact
-
-ethereum event reactor. Component of the ethereum stack.
-various events like state change on an account or new block found are broadcast to subscribers.
-Broadcasting to subscribers is running on its own routine and globally order preserving.
-
-## Clients
-### subscribe
-
- eventChannel := make(chan ethreact.Event)
- reactor.Subscribe(event, eventChannel)
-
-The same channel can be subscribed to multiple events but only once for each event. In order to allow order of events to be preserved, broadcast of events is synchronous within the main broadcast loop. Therefore any blocking subscriber channels will be skipped, i.e. missing broadcasting events while they are blocked.
-
-### unsubscribe
-
- reactor.Unsubscribe(event, eventChannel)
-
-### Processing events
-
-event.Resource is of type interface{}. The actual type of event.Resource depends on event.Name and may need to be cast for processing.
-
- var event ethreact.Event
- for {
- select {
- case event = <-eventChannel:
- processTransaction(event.Resource.(Transaction))
- }
- }
-
-## Broadcast
-
- reactor := ethreact.New()
- reactor.Start()
- reactor.Post(name, resource)
- reactor.Flush() // wait till all broadcast messages are dispatched
- reactor.Stop() // stop the main broadcast loop immediately (even if there are unbroadcast events left)
-
-
-
diff --git a/ethreact/reactor_test.go b/ethreact/reactor_test.go
deleted file mode 100644
index 801a8abd0..000000000
--- a/ethreact/reactor_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package ethreact
-
-import (
- "fmt"
- "testing"
-)
-
-func TestReactorAdd(t *testing.T) {
- reactor := New()
- ch := make(chan Event)
- reactor.Subscribe("test", ch)
- if reactor.eventHandlers["test"] == nil {
- t.Error("Expected new eventHandler to be created")
- }
- reactor.Unsubscribe("test", ch)
- if reactor.eventHandlers["test"] != nil {
- t.Error("Expected eventHandler to be removed")
- }
-}
-
-func TestReactorEvent(t *testing.T) {
- var name string
- reactor := New()
- // Buffer the channel, so it doesn't block for this test
- cap := 20
- ch := make(chan Event, cap)
- reactor.Subscribe("even", ch)
- reactor.Subscribe("odd", ch)
- reactor.Post("even", "disappears") // should not broadcast if engine not started
- reactor.Start()
- for i := 0; i < cap; i++ {
- if i%2 == 0 {
- name = "even"
- } else {
- name = "odd"
- }
- reactor.Post(name, i)
- }
- reactor.Post("test", cap) // this should not block
- i := 0
- reactor.Flush()
- close(ch)
- for event := range ch {
- fmt.Printf("%d: %v", i, event)
- if i%2 == 0 {
- name = "even"
- } else {
- name = "odd"
- }
- if val, ok := event.Resource.(int); ok {
- if i != val || event.Name != name {
- t.Error("Expected event %d to be of type %s and resource %d, got ", i, name, i, val)
- }
- } else {
- t.Error("Unable to cast")
- }
- i++
- }
- if i != cap {
- t.Error("excpected exactly %d events, got ", i)
- }
- reactor.Stop()
-}