An simple post/receive eventbus.
中文 README
- My english is not good enough, so i use google translate to complete this README.
- 'ABC' is for 'available but chaos'.
- Async and name based post/receive
- Provide announcement (explain)
- Implemented by the callback
- All receivers will be executed in the background queue
All receive callbacks will be executed in the background queue
It will be effective until it is canceled. This is means when the new receiver register, it will receive all 'announcement' that have not been canceled .
'announcement' can be canceled.
duemunk/Async is awesome!
for cocoapods:
pod 'ABCEventBus'
or add the file to your project directly
ABCEventBus provides a set of class method, so use it just like this:
ABCEventBus.Post(...)
receiver must conform ABCMessageReceiver protocol
protocol ABCMessageReceiver: class {
func Receive(_ message: ABCMessage)
}
//register an event receiver
RegisterEventReceiver(_ receiver: ABCMessageReceiver, for name: String)
//register an announcement receiver
RegisterAnnouncementReceiver(_ receiver: ABCMessageReceiver, for name: String)
//deregister event
DeregisterEvent(from name: String, for receiver: ABCMessageReceiver)
//deregister announcement
DeregisterAnnouncement(from name: String, for receiver: ABCMessageReceiver)
//post an event
Post(for name: String, data: Any?)
//publish an annountment
Publish(for name: String, data: Any?) -> ABCAnnouncement
//cancel announcement
Cancel(announcement: ABCAnnouncement, from name: String)
//cancel all announcement
CancelAllAnnouncement(from name: String)
There is no examples because ABCEventBus is very simple. Everything you want to know is in the code.
The source is made available under the MIT license.