Events#

Introduction#

Events allow you to run functions in parallel by using event objects. Instead of calling functions or threads one after another, events let you register functions and then trigger them all at once. Each registered function runs in its own thread, so your robot can do multiple things—like blinking TouchLEDs and driving—at the same time.

Below is a list of available methods and constructors:

  • Event – Creates a new event object.

  • broadcast – Triggers all registered functions in an event object to run in parallel.

  • broadcast_and_wait – Triggers all registered functions in an event object and waits for them to finish before continuing.

  • event – Registers a function to the event object, optionally with arguments.

Create an Event Object#

The Event constructor is used to create an event object that manages function execution in separate threads.

Usage:
Event()

Parameter

description

This constructor has no parameters.

# Example coming soon

Broadcast#

broadcast triggers an event, starting all registered functions in separate threads. This method does not pause execution of any subsequent functions.

Usage:
event.broadcast()

parameter

description

event

The name of the previously created event object.

# Example coming soon

Broadcast and wait#

broadcast_and_wait starts an event but waits for all registered functions to finish before continuing with subsequent functions.

Usage:
event.broadcast_and_wait()

parameter

description

event

The name of the previously created event object.

# Example coming soon

Register Functions to an Event#

When you register a function to an event, it will execute in a separate thread when the event is broadcasted.

Usage:
event(callback, args)

Parameter

Description

event

The name of the previously created event object.

callback

A function that is previously defined to execute when the event is broadcasted.

args

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

# Example coming soon