:@schedule

@schedule

Wrap an expression in a Task and add it to the local machine's scheduler queue.

Examples

  1. Schedule a task for execution:

    julia> @schedule begin
             println("This is a scheduled task")
           end

    This example schedules a task to run the given expression, which prints "This is a scheduled task". The task will be added to the local machine's scheduler queue.

  2. Schedule a task with arguments:

    julia> @schedule begin
             function add(a, b)
               println(a + b)
             end
             add(3, 5)
           end

    In this example, a task is scheduled to execute the add function with arguments 3 and 5. The result, 8, will be printed.

  3. Schedule multiple tasks:

    julia> @schedule begin
             println("Task 1")
           end
    
    julia> @schedule begin
             println("Task 2")
           end

    Here, two tasks are scheduled to run in parallel. The first task will print "Task 1" and the second task will print "Task 2".

Common mistake example:

julia> @schedule
ERROR: syntax: "schedule" expression not properly terminated

This example demonstrates a common mistake where the @schedule macro is used without providing an expression to execute. It's important to always provide a valid expression enclosed within begin and end when using @schedule.

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: