LEARN VOID / DATA & BEHAVIOR

Events

Connect objects through ordered notifications.

Complete program for the synchronous entry adapter. The result below is the returned integer.

events.voidDownload source
struct sensor:
    event measured: func(i32)

func (source sensor) publish(reading: i32):
    source.measured.emit(reading)

struct display:
    reading: i32

func (screen display) show(reading: i32):
    screen.reading = reading

func entry(first_reading: i32) -> i32:
    var source = sensor()
    var screen = display()
    source.measured += screen.show
    source.publish(first_reading)
    source.publish(first_reading + 1)
    return screen.reading
Input 5Expected result 6

Declare a reading notification

The sensor owns a measured event carrying one integer. Its publish method is allowed to emit that event; subscribers do not acquire emission authority.

Subscribe a display method

source.measured += screen.show connects the display. The sensor publishes two successive readings. The display first stores the input, then replaces it with the next reading; input 5 leaves screen.reading at 6.

Know when delivery completes

Delivery is synchronous and ordered, so both updates finish before the return. Strong subscriptions keep their receivers alive. Multiple handlers run in subscription order; -= removes the latest matching subscription. Events do not implicitly create async tasks.