forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#33 from ethersphere/feature/ethutil-refactor
ethreact - Feature/ethutil refactor
- Loading branch information
Showing
11 changed files
with
353 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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) | ||
|
||
|
||
|
Oops, something went wrong.