Files
Yukihiro "Matz" Matsumoto 2a124a704f mruby-task: add comprehensive examples demonstrating task features
added six new examples:
- simple.rb: basic task creation and execution
- priority.rb: priority-based scheduling
- suspend_resume.rb: manual task control
- inspection.rb: task status and inspection methods
- statistics.rb: scheduler monitoring with Task.stat
- producer_consumer.rb: task coordination pattern

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-10 17:44:31 +09:00

42 lines
909 B
Ruby

# Priority Scheduling Example
# Lower priority values = higher priority (0 is highest)
puts "=== Priority Scheduling Demo ==="
puts
# Create tasks with different priorities
low_priority = Task.new(name: "low-priority", priority: 200) do
5.times do |i|
puts " [Low Priority] iteration #{i}"
sleep 0.1
end
end
high_priority = Task.new(name: "high-priority", priority: 50) do
5.times do |i|
puts "[High Priority] iteration #{i}"
sleep 0.1
end
end
medium_priority = Task.new(name: "medium-priority", priority: 128) do
5.times do |i|
puts " [Medium Priority] iteration #{i}"
sleep 0.1
end
end
puts "Created 3 tasks with different priorities:"
puts " High: priority=50"
puts " Medium: priority=128"
puts " Low: priority=200"
puts
puts "Tasks will run in priority order (highest first)"
puts
# Run the scheduler
Task.run
puts
puts "=== All tasks completed ==="