Represents a uloop task instance as returned by task().
const task = uloop.task(…);
task.pid();
task.finished();
task.kill();
- Source
- See
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 true
if the task function has already run to completion, otherwise returns false
.
// 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");
- Source
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 true
when the task process was successfully terminated. Returns null
on error, such as when the process has already terminated.
// 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`);
- Source
pid() → {number}
Returns the process ID.
This method returns the process ID (PID) of the underlying forked process launched by task().
The process ID (PID) of the forked task process.
const task = uloop.task(…);
printf("Process ID: %d\n", task.pid());
- Source