1
- [ Travis Widget ] : https://img.shields.io/travis/kataras/go-events.svg?style=flat-square
2
- [ Travis ] : http://travis-ci.org/kataras/go-events
3
- [ License Widget ] : https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square
4
- [ License ] : https://github.com/kataras/go-events/blob/master/LICENSE
5
- [ Release Widget ] : https://img.shields.io/badge/release-v0.0.1-blue.svg?style=flat-square
6
- [ Release ] : https://github.com/kataras/go-events/releases
7
- [ Chat Widget ] : https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square
8
- [ Chat ] : https://kataras.rocket.chat/channel/go-events
9
- [ ChatMain ] : https://kataras.rocket.chat/channel/go-events
10
- [ ChatAlternative ] : https://gitter.im/kataras/go-events
11
- [ Report Widget ] : https://img.shields.io/badge/report%20card-A%2B-F44336.svg?style=flat-square
12
- [ Report ] : http://goreportcard.com/report/kataras/go-events
13
- [ Documentation Widget ] : https://img.shields.io/badge/docs-reference-5272B4.svg?style=flat-square
14
- [ Documentation ] : https://godoc.org/github.com/kataras/go-events
15
- [ Language Widget ] : https://img.shields.io/badge/powered_by-Go-3362c2.svg?style=flat-square
16
- [ Language ] : http://golang.org
17
- [ Platform Widget ] : https://img.shields.io/badge/platform-All-yellow.svg?style=flat-square
18
- [ Awesome Widget ] : https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg?style=flat-square
19
- [ Awesome WidgetAlternative ] : https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square
20
- [ Awesome ] : https://github.com/avelino/awesome-go
21
-
22
1
<p align =" center " >
23
2
<img src =" /logo.jpg " height =" 400 " >
24
- </p >
3
+ <br />
4
+
5
+ <a href =" https://travis-ci.org/kataras/go-events " ><img src =" https://img.shields.io/travis/kataras/go-events.svg?style=flat-square " alt =" Build Status " ></a >
6
+
7
+
8
+ <a href =" https://github.com/avelino/awesome-go " ><img src =" https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square " alt =" Awesome GoLang " ></a >
9
+
10
+ <a href =" http://goreportcard.com/report/kataras/go-events " ><img src =" https://img.shields.io/badge/-A%2B-F44336.svg?style=flat-square " alt =" Report A+ " ></a >
11
+
12
+
13
+ <a href =" https://github.com/kataras/go-events/blob/master/LICENSE " ><img src =" https://img.shields.io/badge/%20license-MIT%20-E91E63.svg?style=flat-square " alt =" License " ></a >
14
+
15
+
16
+
17
+ <a href =" https://github.com/kataras/go-events/releases " ><img src =" https://img.shields.io/badge/%20release%20-%20v0.0.2-blue.svg?style=flat-square " alt =" Releases " ></a >
18
+
19
+ <a href =" https://godoc.org/github.com/kataras/go-events " ><img src =" https://img.shields.io/badge/%20docs-reference-5272B4.svg?style=flat-square " alt =" Read me docs " ></a >
20
+
21
+ <a href =" https://kataras.rocket.chat/channel/go-events " ><img src =" https://img.shields.io/badge/%20community-chat-00BCD4.svg?style=flat-square " alt =" Chat " ></a >
25
22
26
- # Events [ ![ Travis Widget ]] [ Travis ] [ ![ Awesome Widget ]] [ Awesome ] [ ![ License Widget ]] [ License ] [ ![ Release Widget ]] [ Release ]
23
+ < br />< br />
27
24
28
- Simple nodejs-style EventEmmiter for Go Programming Language.
25
+ Simple EventEmmiter for Go Programming Language. Inspired by < a href = " https://nodejs.org/api/events.html " >Nodejs EventEmitter</ a > .
29
26
27
+ </p >
30
28
31
29
32
30
Quick view
33
31
------------
32
+ ` New() EventEmmiter // New returns a new, empty, EventEmmiter `
33
+
34
+
35
+ ``` go
36
+ // AddListener is an alias for .On(eventName, listener).
37
+ AddListener (EventName, ...Listener )
38
+ // Emit fires a particular event,
39
+ // Synchronously calls each of the listeners registered for the event named
40
+ // eventName, in the order they were registered,
41
+ // passing the supplied arguments to each.
42
+ Emit (EventName, ...interface {})
43
+ // EventNames returns an array listing the events for which the emitter has registered listeners.
44
+ // The values in the array will be strings.
45
+ EventNames () []EventName
46
+ // GetMaxListeners returns the max listeners for this emmiter
47
+ // see SetMaxListeners
48
+ GetMaxListeners () int
49
+ // ListenerCount returns the length of all registered listeners to a particular event
50
+ ListenerCount (EventName) int
51
+ // Listeners returns a copy of the array of listeners for the event named eventName.
52
+ Listeners (EventName) []Listener
53
+ // On registers a particular listener for an event, func receiver parameter(s) is/are optional
54
+ On (EventName, ...Listener )
55
+ // Once adds a one time listener function for the event named eventName.
56
+ // The next time eventName is triggered, this listener is removed and then invoked.
57
+ Once (EventName, ...Listener )
58
+ // RemoveAllListeners removes all listeners, or those of the specified eventName.
59
+ // Note that it will remove the event itself.
60
+ // Returns an indicator if event and listeners were found before the remove.
61
+ RemoveAllListeners (EventName) bool
62
+ // Clear removes all events and all listeners, restores Events to an empty value
63
+ Clear ()
64
+ // SetMaxListeners obviously this function allows the MaxListeners
65
+ // to be decrease or increase. Set to zero for unlimited
66
+ SetMaxListeners (int )
67
+ // Len returns the length of all registered events
68
+ Len () int
69
+ ```
34
70
35
- - ` New ` returns a new, empty EventEmmiter
36
- - ` On ` is the func which registers the event listeners for a specific event
37
- - ` Emit ` fires a particular event, this will call all functions(listeners) registered to this particular event
38
- - ` Remove ` remove all registered listeners from a particular event
39
- - ` Len ` returns the length of all registered events
40
- - ` LenListeners ` returns the length of all registered listeners to a particular event
41
71
42
72
``` go
43
73
import " github.com/kataras/go-events"
@@ -81,18 +111,16 @@ events.On("my_event", func(payload ...interface{}) {
81
111
})
82
112
83
113
println (events.Len ()) // prints 1
84
- println (events.LenListeners (" my_event" )) // prints 2
114
+ println (events.ListenerCount (" my_event" )) // prints 2
85
115
86
116
// Remove our event, when/if we don't need this or we want to clear all of its listeners
87
- events.Remove (" my_event" )
117
+ events.RemoveAllListeners (" my_event" )
88
118
89
119
println (events.Len ()) // prints 0
90
- println (events.LenListeners (" my_event" )) // prints 0
120
+ println (events.ListenerCount (" my_event" )) // prints 0
91
121
92
122
93
123
```
94
- [ ![ Documentation Widget]] [ Documentation ] [ ![ Chat Widget]] [ Chat ]
95
-
96
124
Installation
97
125
------------
98
126
@@ -102,7 +130,6 @@ The only requirement is the [Go Programming Language](https://golang.org/dl).
102
130
$ go get -u github.com/kataras/go-events
103
131
```
104
132
105
- [ ![ Language Widget]] [ Language ] ![ Platform Widget]
106
133
107
134
FAQ
108
135
------------
@@ -112,7 +139,7 @@ Explore [these questions](https://github.com/kataras/go-events/issues?go-events=
112
139
Versioning
113
140
------------
114
141
115
- Current: v0.0.1
142
+ Current: v0.0.2
116
143
117
144
Read more about Semantic Versioning 2.0.0
118
145
@@ -135,18 +162,12 @@ Contributing
135
162
136
163
If you are interested in contributing to the go-events project, please make a PR.
137
164
138
- [ ![ Report Widget]] [ Report ]
139
-
140
-
141
- README template
142
- ------------
143
-
144
- https://github.com/kataras/github-go-readme
145
-
146
-
147
165
License
148
166
------------
149
167
150
168
This project is licensed under the MIT License.
151
169
152
170
License can be found [ here] ( LICENSE ) .
171
+
172
+ [ Chat Widget ] : https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square
173
+ [ Chat ] : https://kataras.rocket.chat/channel/go-events
0 commit comments