event

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 0 Imported by: 66

Documentation

Overview

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.Stop()` or `Context.Continue()` to call a function when an event is or is not cancelled respectively. Such events may be cancelled by passing the created `Context` to the end user, who is then able to cancel it by calling `Context.Cancel()`. Additionally, a `Context.After()` function is exported, which may be used to call code after the `Context.Stop()` and `Context.Continue()` functions are called. Code performing the event should be run in these functions, so that the `Context.After()` function is able to run code of the end user immediately after the event itself happens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context represents the context of an event. Handlers of an event may call methods on the context to change the result of the event.

func C

func C() *Context

C returns a new event context.

func (*Context) After

func (ctx *Context) After(f func(cancelled bool))

After calls the function passed after the action of the event has been completed, either by a call to (*Context).Continue() or (*Context).Stop(). After can be executed multiple times to attach more functions to be called after the event is executed.

func (*Context) Cancel

func (ctx *Context) Cancel()

Cancel cancels the context.

func (*Context) Cancelled added in v0.5.0

func (ctx *Context) Cancelled() bool

Cancelled returns whether the context has been cancelled.

func (*Context) Continue

func (ctx *Context) Continue(f func())

Continue calls the function f if the context is not cancelled. If it is cancelled, Continue will return immediately. These functions are not generally useful for handling events. See After() for executing code after the event happens.

func (*Context) Stop

func (ctx *Context) Stop(f func())

Stop calls the function f if the context is cancelled. If it is not cancelled, Stop will return immediately. Stop does the opposite of Continue. These functions are not generally useful for handling events. See After() for executing code after the event happens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL