From 67528cf9709519458ab5500cb7cf54664dd20167 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 21 Jul 2014 15:10:56 +0100 Subject: [PATCH] ethreact/README.md --- ethreact/README.md | 28 ++++++++++++++++++++++++++++ ethreact/reactor.go | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ethreact/README.md diff --git a/ethreact/README.md b/ethreact/README.md new file mode 100644 index 0000000000..61af8a5729 --- /dev/null +++ b/ethreact/README.md @@ -0,0 +1,28 @@ +## Reactor + +Reactor is the internal broadcast engine that allows components to be notified of ethereum stack events such as finding new blocks or change in state. +Event notification is handled via subscription: + + var blockChan = make(chan ethreact.Event, 10) + reactor.Subscribe("newBlock", blockChan) + +ethreact.Event broadcast on the channel are + + type Event struct { + Resource interface{} + Name string + } + +Resource is polimorphic depending on the event type and should be typecast before use, e.g: + + b := <-blockChan: + block := b.Resource.(*ethchain.Block) + +Events are guaranteed to be broadcast in order but the broadcast never blocks or leaks which means while the subscribing event channel is blocked (e.g., full if buffered) further messages will be skipped. + +The engine allows arbitrary events to be posted and subscribed to. + + ethereum.Reactor().Post("newBlock", newBlock) + + + \ No newline at end of file diff --git a/ethreact/reactor.go b/ethreact/reactor.go index a26f82a97f..7fe2356db7 100644 --- a/ethreact/reactor.go +++ b/ethreact/reactor.go @@ -58,7 +58,7 @@ func (e *EventHandler) Remove(ch chan Event) int { return len(e.chans) } -// Basic reactor resource +// Basic reactor event type Event struct { Resource interface{} Name string