Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag interface {
// IsSet returns true if the flag is set.
// The method uses an atomic boolean internally and is non-blocking.
IsSet() bool
// Wait waits for the flag to be set.
Wait() <-chan struct{}
}
Flag is a read-only boolean flag that can be waited on until set.
Example:
serving := async.UnsetFlag()
func handle(ctx Context, req *request) {
if !serving.Get() { // just to show Get in example
select {
case <-ctx.Wait():
return ctx.Status()
case <-serving.Wait():
}
}
// ... handle request
}
func ReverseFlag ¶
ReverseFlag returns a new flag which reverses the original one.
type MutFlag ¶
type MutFlag interface {
Flag
// Set sets the flag and notifies the waiters.
Set()
// Unset unsets the flag and replaces its wait channel with an open one.
Unset()
}
MutFlag is a routine-safe boolean flag that can be set, reset, and waited on until set.
Example:
serving := async.UnsetFlag()
func serve() {
s.serving.Set()
defer s.serving.Unset()
// ... start server ...
}
func handle(ctx Context, req *request) {
select {
case <-ctx.Wait():
return ctx.Status()
case <-serving.Wait():
}
// ... handle request
}
Click to show internal directories.
Click to hide internal directories.