mostafa-asg / race

:checkered_flag: Race between http requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race

Package race provides functionality to call http requests simultaneously and get the result from the fastest one.

Usage

req1, err := http.NewRequest("GET", "slowServer.url", nil)
req2, err := http.NewRequest("GET", "fastServer.url", nil)
req3, err := http.NewRequest("GET", "backupServer.url", nil)

// Starts all 3 requests concurrently and returns
// the *http.Response got from fastest server
res, err := race.Between(req1, req2, req3)

Or if you prefer starting a request first and only if it takes too long, starts the other, use FirstThenStart:

// First start `req1` and after 1 second start the other requests (req2 and req3)
res, err := race.FirstThenStart(req1, 1*time.Second, req2, req3)

About

:checkered_flag: Race between http requests

License:MIT License


Languages

Language:Go 100.0%