Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chakrit/machine-gun
Fire HTTP requests in ruby like a machine gun.
https://github.com/chakrit/machine-gun
Last synced: about 20 hours ago
JSON representation
Fire HTTP requests in ruby like a machine gun.
- Host: GitHub
- URL: https://github.com/chakrit/machine-gun
- Owner: chakrit
- Created: 2015-12-25T06:38:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-28T09:00:07.000Z (almost 9 years ago)
- Last Synced: 2024-04-15T12:21:32.518Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 9.23 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
Awesome Lists containing this project
README
# MACHINE-GUN.rb
Fire asynchronous HTTP requests **in ruby** like a machine gun.
Utilizing the power of goroutines.# INSTALL
```ruby
gem 'machine-gun'
```# USE
**DON'T** do this:
```ruby
require 'net/http'responses = [
Net::HTTP.get('example.com', '/one.html'),
Net::HTTP.get('example.com', '/two.html'),
Net::HTTP.get('example.com', '/three.html')
]
```This will perform HTTP requests serially, waiting before the last one finish before the
next one starts. This will also blocks your ruby Thread for the total duration of the 3
calls.**INSTEAD DO** this:
```ruby
require 'machine-gun'responses = [
MachineGun::Request.new(:get, 'http://example.com/one.html', { })
MachineGun::Request.new(:get, 'http://example.com/two.html', { })
MachineGun::Request.new(:get, 'http://example.com/three.html', { })
].map { |req| req.response }
```This will fire 3 HTTP requests simultaneously in the background (more specifically, in a
hidden goroutine). And then waits for the result. This will blocks your ruby Thread only
for the duration of the longest request.# LICENSE
MIT