Skip to main content

Callback

The Callback type represents a function that can be called dynamically. Unlike a normal function call, callbacks are dispatched at runtime rather than at compile time, and so they can only have a simple parameter list - no context variables and no named arguments, just a list of positional arguments.

// Block syntax
let callback1 = |name| {
return "Hello, " + name + "!"
}
let greeting = callback1("world") // assigns "Hello, world!" to greeting

// Expression syntax
let callback2 = |name| "Goodbye, " + name + "!"
greeting = callback1("Fred") // assigns "Goodbye, Fred!" to greeting

// Callbacks can be used to customize certain functions
let players = QueryPlayers.OrderBy(|x| x.PlayerName)

All subblock parameters are actually just callbacks.

In other programming languages, callbacks are sometimes called lambdas, delegates, arrow functions, closures, or anonymous functions.

Awaiting a callback

Calling a callback waits for it to fully complete. This includes waiting for any await calls that the callback does. Unlike other programming languages, you do not need to use the await keyword to wait when calling the callback.

info

This works because Easel is a stackful coroutine language, which means it can suspend and resume the execution of any function at any point. In other programming languages you need to specify resume points using the await keyword, but not in Easel.