Skip to content

Instantly share code, notes, and snippets.

@glaucocustodio
Last active December 29, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaucocustodio/025794f8d29edbade8062db83e13baa7 to your computer and use it in GitHub Desktop.
Save glaucocustodio/025794f8d29edbade8062db83e13baa7 to your computer and use it in GitHub Desktop.
Fire and forget http request with em-http-request ruby gem
# You just need to set inactivity_timeout = 0.1 (or any other low number except zero).
# It will trigger the request and wait only 0.1 second for the response. You don't need to define the callbacks as well.
# Example code below:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem "em-http-request"
end
require "eventmachine"
require "em-http-request"
EM.run do
options = {:inactivity_timeout => 0.1}
http = EM::HttpRequest.new("http://localhost:4567", options).get
# http.callback do
# puts "Success."
# p http.response
# end
# http.errback do
# puts "Error."
# end
puts "Sent."
end
# the server will complete processing the request even though it takes more than 0.1s
require 'sinatra'
get '/' do
sleep 5
p 'Put this in your pipe & smoke it!'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment