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

This commit is contained in:
2026-07-09 08:33:57 +08:00
commit 26ed99fda6
845 changed files with 75419 additions and 0 deletions
+28
View File
@@ -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
}
+6
View File
@@ -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