istaskdone

istaskdone(task) -> Bool

Tell whether a task has exited.

Examples

  1. Check if a task has exited:

    julia> task = @task sleep(2);
    julia> istaskdone(task)
    false

    This example creates a task that sleeps for 2 seconds. The istaskdone function is then used to check if the task has exited (i.e., finished executing). In this case, the task has not yet exited, so it returns false.

  2. Handle a completed task:

    julia> task = @task begin
               println("Executing task...")
               sleep(2)
               println("Task completed!")
           end
    julia> schedule(task)
    julia> istaskdone(task)
    true

    Here, a task is created that prints a message, sleeps for 2 seconds, and then prints another message. The task is scheduled using schedule and then istaskdone is used to check if the task has exited. Since the task has completed its execution, it returns true.

  3. Check the status of a failed task:
    julia> task = @task error("Oops, something went wrong!")
    julia> schedule(task)
    julia> istaskdone(task)
    true

    In this example, a task is created that intentionally throws an error. The task is scheduled and then istaskdone is used to check its status. Even though the task encountered an error and exited, istaskdone still returns true.

Common mistake example:

julia> task = @task sleep(2);
julia> istaskdone()
ERROR: MethodError: no method matching istaskdone()

In this example, the istaskdone function is called without providing the task argument. It's important to pass the task object to the function for it to work correctly.

See Also

:@async, :@schedule, :@task, Condition, consume, interrupt, istaskdone, istaskstarted, lock, notify, ReentrantLock, schedule, Task, task_local_storage, unlock, wait, yield, yieldto,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: