Last active
December 29, 2020 17:20
-
-
Save glaucocustodio/025794f8d29edbade8062db83e13baa7 to your computer and use it in GitHub Desktop.
Fire and forget http request with em-http-request ruby gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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