up3
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package event
|
||||
|
||||
// Context represents the context of an event. Handlers of an event may call methods on the context to change
|
||||
// the result of the event.
|
||||
type Context[T any] struct {
|
||||
cancel bool
|
||||
val T
|
||||
}
|
||||
|
||||
// C returns a new event context.
|
||||
func C[T any](v T) *Context[T] {
|
||||
return &Context[T]{val: v}
|
||||
}
|
||||
|
||||
// Val returns the subject of the Context.
|
||||
func (ctx *Context[T]) Val() T {
|
||||
return ctx.val
|
||||
}
|
||||
|
||||
// Cancelled returns whether the context has been cancelled.
|
||||
func (ctx *Context[T]) Cancelled() bool {
|
||||
return ctx.cancel
|
||||
}
|
||||
|
||||
// Cancel cancels the context.
|
||||
func (ctx *Context[T]) Cancel() {
|
||||
ctx.cancel = true
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Package event exposes a single exported `Context` type that may be used to influence the execution flow of events
|
||||
// that occur on a server.
|
||||
// Generally, the caller of `event.C()` calls `Context.Cancelled()` to check if the `Context` was cancelled (using
|
||||
// `Context.Cancel()`) by whatever code it was passed to.
|
||||
// who is then able to cancel it by calling `Context.Cancel()`.
|
||||
package event
|
||||
Reference in New Issue
Block a user