uloop. task

Represents a uloop task instance as returned by task().

Example
const task = uloop.task(…);

task.pid();
task.finished();

task.kill();

Methods

finished() → {boolean}

Checks if the task ran to completion.

This method checks if the task function has already run to completion. It returns a boolean value indicating whether the task function has finished executing.

Returns: boolean

Returns true if the task function has already run to completion, otherwise returns false.

Example
// Check if the task function has finished executing
const isFinished = task.finished();

if (isFinished)
    printf("Task function has finished executing\n");
else
    printf("Task function is still running\n");

kill() → {boolean}nullable

Terminates the task process.

This method terminates the task process. It sends a termination signal to the task process, causing it to exit. Returns true on success, indicating that the task process was successfully terminated. Returns null on error, such as when the task process has already terminated.

Returns: boolean

Returns true when the task process was successfully terminated. Returns null on error, such as when the process has already terminated.

Example
// Terminate the task process
const success = task.kill();

if (success)
    printf("Task process terminated successfully\n");
else
    die(`Error terminating task process: ${uloop.error()}\n`);

pid() → {number}

Returns the process ID.

This method returns the process ID (PID) of the underlying forked process launched by task().

Returns: number

The process ID (PID) of the forked task process.

Example
const task = uloop.task(…);

printf("Process ID: %d\n", task.pid());