Sha256: 3b565b2f661850db91f798564c2a60a1798e77be2a3740ec3a456379c2f3eb8c

Contents?: true

Size: 398 Bytes

Versions: 6

Compression:

Stored size: 398 Bytes

Contents

#!/usr/bin/env ruby

require 'async'
require 'async/io/notification'

def defer(*args, &block)
	Async do
		notification = Async::IO::Notification.new
		
		thread = Thread.new(*args) do
			yield
		ensure
			notification.signal
		end
		
		notification.wait
		thread.join
	end
end

Async do
	10.times do
		defer do
			puts "I'm going to sleep"
			sleep 1
			puts "I'm going to wake up"
		end
	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
async-io-1.29.0 examples/defer/worker.rb
async-io-1.28.0 examples/defer/worker.rb
async-io-1.27.7 examples/defer/worker.rb
async-io-1.27.6 examples/defer/worker.rb
async-io-1.27.5 examples/defer/worker.rb
async-io-1.27.4 examples/defer/worker.rb