Module completion

Lua bindings for kernel completion mechanisms.

This library allows Lua scripts to create, signal, and wait on kernel completion objects.

Task completion is a synchronization mechanism used to coordinate the execution of multiple threads. It allows threads to wait for a specific event to occur before proceeding, ensuring certain tasks are complete.

Functions

complete () Signals a completion.
wait ([timeout]) Waits for a completion to be signaled.

completion

new () Creates a new kernel completion object.


Functions

complete ()
Signals a completion. This wakes up one task waiting on this completion object. Corresponds to the kernel's complete() function.

Returns:

    nil

See also:

Usage:

    -- Assuming 'c' is a completion object returned by completion.new()
    c:complete()
wait ([timeout])
Waits for a completion to be signaled. This function will block the current Lua runtime until the completion is signaled, an optional timeout occurs, or the wait is interrupted. The Lunatik runtime invoking this method must be sleepable. Corresponds to the kernel's wait_for_completion_interruptible_timeout().

Parameters:

  • timeout integer Optional timeout in milliseconds. If omitted or set to MAX_SCHEDULE_TIMEOUT (a large kernel-defined constant), waits indefinitely. (optional)

Returns:

  1. boolean true if the completion was signaled successfully before timeout or interruption.
  2. nil,string nil and an error message if the wait did not complete successfully. The message will be one of: - "timeout": The specified timeout elapsed. - "interrupt": The waiting task was interrupted by a signal (e.g., thread.stop()). If the wait fails for other kernel internal reasons, the C code might push "unknown", though typical documented returns are for timeout and interrupt. - "unknown": An unexpected error occurred during the wait.

See also:

Usage:

    -- Assuming 'c' is a completion object
    local success, err_msg = c:wait(1000) -- Wait for up to 1 second
    if success then
      print("Completion received!")
    else
      print("Wait failed: " .. err_msg)
    end

completion

new ()
Creates a new kernel completion object. Initializes a struct completion and returns it wrapped as a Lua userdata object of type completion.

Returns:

    completion A new completion object.

Usage:

    local c = completion.new()
generated by LDoc 1.5.0 Last updated 2025-06-27 17:53:55