:@schedule
@schedule
Wrap an expression in a Task and add it to the local machine's scheduler queue.
Examples
-
Schedule a task for execution:
julia> @schedule begin println("This is a scheduled task") endThis 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.
-
Schedule a task with arguments:
julia> @schedule begin function add(a, b) println(a + b) end add(3, 5) endIn this example, a task is scheduled to execute the
addfunction with arguments3and5. The result,8, will be printed. -
Schedule multiple tasks:
julia> @schedule begin println("Task 1") end julia> @schedule begin println("Task 2") endHere, 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.