Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
dac4a8f1
Commit
dac4a8f1
authored
Oct 16, 2014
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event: add some documentation
parent
f5b8775b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
event.go
event/event.go
+9
-0
example_test.go
event/example_test.go
+42
-0
No files found.
event/event.go
View file @
dac4a8f1
...
@@ -7,8 +7,16 @@ import (
...
@@ -7,8 +7,16 @@ import (
"sync"
"sync"
)
)
// Subscription is implemented by event subscriptions.
type
Subscription
interface
{
type
Subscription
interface
{
// Chan returns a channel that carries events.
// Implementations should return the same channel
// for any subsequent calls to Chan.
Chan
()
<-
chan
interface
{}
Chan
()
<-
chan
interface
{}
// Unsubscribe stops delivery of events to a subscription.
// The event channel is closed.
// Unsubscribe can be called more than once.
Unsubscribe
()
Unsubscribe
()
}
}
...
@@ -21,6 +29,7 @@ type TypeMux struct {
...
@@ -21,6 +29,7 @@ type TypeMux struct {
stopped
bool
stopped
bool
}
}
// ErrMuxClosed is returned when Posting on a closed TypeMux.
var
ErrMuxClosed
=
errors
.
New
(
"event: mux closed"
)
var
ErrMuxClosed
=
errors
.
New
(
"event: mux closed"
)
// NewTypeMux creates a running mux.
// NewTypeMux creates a running mux.
...
...
event/example_test.go
0 → 100644
View file @
dac4a8f1
package
event
import
"fmt"
func
ExampleTypeMux
()
{
type
someEvent
struct
{
I
int
}
type
otherEvent
struct
{
S
string
}
type
yetAnotherEvent
struct
{
X
,
Y
int
}
var
mux
TypeMux
// Start a subscriber.
done
:=
make
(
chan
struct
{})
sub
:=
mux
.
Subscribe
(
someEvent
{},
otherEvent
{})
go
func
()
{
for
event
:=
range
sub
.
Chan
()
{
fmt
.
Printf
(
"Received: %#v
\n
"
,
event
)
}
fmt
.
Println
(
"done"
)
close
(
done
)
}()
// Post some events.
mux
.
Post
(
someEvent
{
5
})
mux
.
Post
(
yetAnotherEvent
{
X
:
3
,
Y
:
4
})
mux
.
Post
(
someEvent
{
6
})
mux
.
Post
(
otherEvent
{
"whoa"
})
// Stop closes all subscription channels.
// The subscriber goroutine will print "done"
// and exit.
mux
.
Stop
()
// Wait for subscriber to return.
<-
done
// Output:
// Received: event.someEvent{I:5}
// Received: event.someEvent{I:6}
// Received: event.otherEvent{S:"whoa"}
// done
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment