Skip to content

Commit

Permalink
Add multi-threaded example
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jul 28, 2024
1 parent 20053fb commit a28ef0b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions example/multi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

require 'agoo'

Agoo::Log.configure(dir: '',
console: true,
classic: true,
colorize: true,
states: {
INFO: true,
DEBUG: false,
connect: true,
request: true,
response: true,
eval: true,
push: false,
})

Agoo::Server.init(6464, 'root', thread_count: 4)

class MyHandler
def call(req)
[ 200, { }, [ "hello world" ] ]
end
end

handler = MyHandler.new
# Register the handler before calling start.
Agoo::Server.handle(:GET, "/hello", handler)

Agoo::Server.start()

# Agoo::Server.start() returns immediately after starting the handler
# threads. This allows additional work to take place after the start. If there
# is no other action needed other than to let the server handle requests then
# a simple sleep loop can be used to keep the app from exiting.
while true
sleep(1)
end

# To run this example type the following then go to a browser and enter a URL of localhost:6464/hello.
# ruby hello.rb

0 comments on commit a28ef0b

Please sign in to comment.