Help us shape the future of Go! Take the 2026 Go Developer Survey

eventsmod

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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 For

func For(env value.Env) *Loop

For returns the loop of the interpreter env belongs to.

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

func (l *Loop) Poll(fn func() error, every time.Duration) (remove func())

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.

func (*Loop) Post

func (l *Loop) Post(fn func() error)

Post makes fn run on the interpreter's goroutine, inside events::run(), after the events posted before it. It may be called from any goroutine. fn may call Kukel functions (env.Call); an error it returns is treated like an exception of a handler.

Jump to

Keyboard shortcuts

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