Project

General

Profile

Feature #13821 » wait.rb

use-case - cremes (Chuck Remes), 08/16/2017 05:13 PM

 
require_relative 'lib/async-await'

Thread.abort_on_exception = true

# Wait docs...
class Wait
include AsyncAwait

def dofirst
async do
puts 'Synchronously print dofirst.'
result = await { dosecond }
puts 'dosecond is complete'
result
end
end

def dosecond
async do
puts 'Synchronously print dosecond from async task.'
slept = await { sleep 3 }
puts 'Sleep complete'
slept
end
end

def run
task = dofirst
puts 'Received task'
p AsyncAwait::Task.await(task)
end
end

Wait.new.run

# Expected output:
# Synchronous print dofirst.
# Received task
# Synchronously print dosecond from async task.
# Sleep complete
# dosecond is complete
# 3

(2-2/2)