Skip to content

Commit

Permalink
Fix bug in HTTP server example
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Jun 3, 2010
1 parent 611ec87 commit 1bd0ead
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions examples/fiber-ring.rb
@@ -0,0 +1,34 @@

require 'fiber'

# Number of rounds.
M = ARGV[0] ? Integer(ARGV[0]) : 10

# Number of elements.
N = ARGV[1] ? Integer(ARGV[1]) : 64

def node(output, id)
Fiber.new do |i|
while true
i = output.transfer(i.succ)
end
end
end

LAST = Fiber.new do |i|
M.times do
puts i
i = FIRST.transfer(i.succ)
end
i = Fiber.yield(i)
end

FIRST = (0...N).inject(LAST) {|chan, id| node(chan, id) }

i = 0
M.times do
FIRST.transfer(i)
i = LAST.resume
end

puts i
2 changes: 1 addition & 1 deletion examples/http_server.rb
Expand Up @@ -28,7 +28,7 @@ def call(env)
message = req.params['message']

if message.nil?
[401, {'Content-Type' => 'text/plain'}, "Please specify a message"]
return [401, {'Content-Type' => 'text/plain'}, "Please specify a message"]
end

puts "Writing message #{message}"
Expand Down

0 comments on commit 1bd0ead

Please sign in to comment.