gobus

所属分类:工具库
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2016-06-21 17:04:33
上 传 者sh-1993
说明:  与Golang一起使用基于内容的事件驱动编程的简单库,
(Simple library to use content-based event-driven programming with Golang,)

文件列表:
.travis.yml (85, 2016-06-21)
LICENSE (1073, 2016-06-21)
bus.go (3717, 2016-06-21)
errors.go (266, 2016-06-21)
examples/ (0, 2016-06-21)
examples/example1.go (571, 2016-06-21)
set.go (1540, 2016-06-21)
subscription.go (1914, 2016-06-21)
testing/ (0, 2016-06-21)
testing/test_subscription.go (1601, 2016-06-21)
types.go (1116, 2016-06-21)

# GoBus [![Build Status](https://travis-ci.org/ar3s3ru/gobus.svg?branch=master)](https://travis-ci.org/ar3s3ru/gobus) Simple asynchronous, content-based event bus for Go. ## Usage GoBus provides a straightforward implementation for an Event Bus.
Start using the Event Bus this way: ```go bus := gobus.NewEventBus() // Un-buffered channel bus := gobus.NewEventBusBuffered(chanSize) // Buffered channel defer bus.Destruct() ``` GoBus can use a buffered and an un-buffered channel to dispatch events as they arrive. Always remember to call ```bus.Destruct()``` at the end of the Event Bus usage, as it's needed for cleanup purposes (closing channels, returning asynchronous goroutines, ...). #### (Un)Subscription You can subscribe (and unsubscribe) one or more listeners to the Event Bus like this: ```go func useString(event string) { // Do something } bus.Subscribe(useString) bus.UnSubscribe(useString) // Method chaining bus.Subscribe(function1).Subscribe(function2).Subscribe(function3). UnSubscribe(function2).UnSubscribe(function3) // Variadic arguments bus.Subscribe(function1, function2, function3) bus.UnSubscribe(function1, function3, function2) // Having fun :-) bus.Subscribe(function1, function2, function3). UnSubscribe(function1, function2, function3) ``` Listeners must be unary procedures, functions with one input argument and no return arguments. Listeners are grouped together by their input argument types (meaning that publishing a string will call every string listeners registered to the bus). #### Publishing You can publish events to the Event Bus this way: ```go bus.Publish("HelloWorld!") // Method chaining bus.Publish("HelloWorld!").Publish(12) ``` Events are pushed to a dispatcher channel which will asynchronously calls all the listeners registered to the event type. Being asynchronous through goroutines, there are no guarantees on the listeners calling order. ## Contributing Biggest contribution towards this library is to use it and give us feedback for further improvements and additions. For direct contributions, branch of from master and do _pull request_. ## License This library is distributed under the MIT License found in the [LICENSE](https://github.com/ar3s3ru/gobus/blob/master/LICENSE) file. Written by Danilo Cianfrone.

近期下载者

相关文件


收藏者