mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
2a124a704f
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>
28 lines
475 B
Ruby
28 lines
475 B
Ruby
# Simple Task Example
|
|
# Basic usage of mruby-task
|
|
|
|
puts "=== Simple Task Demo ==="
|
|
puts
|
|
|
|
# Create a simple task
|
|
Task.new(name: "hello") do
|
|
3.times do |i|
|
|
puts "Hello from task, iteration #{i}"
|
|
sleep 0.5
|
|
end
|
|
end
|
|
|
|
# Create another task
|
|
Task.new(name: "world") do
|
|
3.times do |i|
|
|
puts "World from task, iteration #{i}"
|
|
sleep 0.7
|
|
end
|
|
end
|
|
|
|
# Run the scheduler - blocks until all tasks complete
|
|
puts "Starting tasks..."
|
|
Task.run
|
|
|
|
puts "All tasks completed!"
|