Sha256: 8c2f0af2224b74a585fc3642ae48f8fce2c286317b6d24633ea179c8e872e90a

Contents?: true

Size: 829 Bytes

Versions: 61

Compression:

Stored size: 829 Bytes

Contents

require 'trenni/template'

require 'async'
require 'async/http/body/writable'

# The template, using inline text. The sleep could be anything - database query, HTTP request, redis, etc.
buffer = Trenni::Buffer.new(<<-EOF)
The "\#{self[:count]} bottles of \#{self[:drink]} on the wall" song!

<?r self[:count].downto(1) do |index| ?>
	\#{index} bottles of \#{self[:drink]} on the wall,
	\#{index} bottles of \#{self[:drink]},
	take one down, and pass it around,
	\#{index - 1} bottles of \#{self[:drink]} on the wall.
	
	<?r Async::Task.current.sleep(1) ?>
<?r end ?>
EOF

template = Trenni::Template.new(buffer)

Async do
	body = Async::HTTP::Body::Writable.new

	generator = Async do
		template.to_string({count: 100, drink: 'coffee'}, body)
	end

	while chunk = body.read
		$stdout.write chunk
	end
	
	generator.wait
end.wait

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
async-http-0.52.4 examples/trenni/streaming.rb
async-http-0.52.3 examples/trenni/streaming.rb
async-http-0.52.2 examples/trenni/streaming.rb
async-http-0.52.1 examples/trenni/streaming.rb
async-http-0.52.0 examples/trenni/streaming.rb
async-http-0.51.6 examples/trenni/streaming.rb
async-http-0.51.5 examples/trenni/streaming.rb
async-http-0.51.4 examples/trenni/streaming.rb
async-http-0.51.3 examples/trenni/streaming.rb
async-http-0.51.2 examples/trenni/streaming.rb
async-http-0.51.1 examples/trenni/streaming.rb
async-http-0.51.0 examples/trenni/streaming.rb
async-http-0.50.13 examples/trenni/streaming.rb
async-http-0.50.12 examples/trenni/streaming.rb
async-http-0.50.11 examples/trenni/streaming.rb
async-http-0.50.10 examples/trenni/streaming.rb
async-http-0.50.9 examples/trenni/streaming.rb
async-http-0.50.8 examples/trenni/streaming.rb
async-http-0.50.7 examples/trenni/streaming.rb
async-http-0.50.6 examples/trenni/streaming.rb