Documentation
¶
Overview ¶
Package eventsmod is the native module "events": an event loop that calls Kukel functions when timers expire or other modules post events.
use events;
events::every(1, fn() { println("tick"); });
events::after(3.5, events::stop);
events::run(); // returns when nothing is left, or on stop()
Each interpreter has its own loop. Handlers run one at a time on the interpreter's goroutine, inside events::run(). Other Go modules (a GUI, sockets) feed the loop from their own goroutines with Loop.Post, and keep run() going while they may still deliver events with Loop.Hold.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Timer = &native.Class{ Name: "Timer", Methods: map[string]value.NativeMethod{ "cancel": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) { if _, err := native.Check("events::Timer::cancel", args, 0, 0); err != nil { return value.NilValue, err } t := this.State.(*timer) if !t.cancelled && !t.fired { t.cancelled = true l := For(env) l.active-- if t.index >= 0 { heap.Remove(&l.timers, t.index) } } return value.NilValue, nil }, "active": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) { if _, err := native.Check("events::Timer::active", args, 0, 0); err != nil { return value.NilValue, err } t := this.State.(*timer) return value.MakeBool(!t.cancelled && !t.fired), nil }, }, Show: func(o *value.ObjectObj) string { t := o.State.(*timer) switch { case t.cancelled: return "events::Timer(cancelled)" case t.fired: return "events::Timer(fired)" case t.interval > 0: return "events::Timer(every " + t.every + "s)" } return "events::Timer(once)" }, }
Timer is the class events::Timer: what after() and every() give.
Functions ¶
This section is empty.
Types ¶
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop is the event loop of one interpreter.
func (*Loop) Hold ¶
func (l *Loop) Hold() (release func())
Hold keeps events::run() going (instead of returning when nothing is left) until the returned function is called: for a source that may still post events, such as an open window or socket. It may be called from any goroutine; calling the release function more than once has no effect.
func (*Loop) Poll ¶ added in v0.20.0
Poll has fn called on the interpreter's goroutine about every `every` while events::run() runs: for a source that must be asked for its events from that goroutine, such as a GUI toolkit. An error fn returns is treated like an exception of a handler. Poll is called on the interpreter's goroutine; the returned function stops the calls.