Last active
January 22, 2021 03:58
-
-
Save mvandergrift/20748e7de5aaad74e4fc690666717a1c to your computer and use it in GitHub Desktop.
Initialize API clients to feed GO channel for consumer to process
This file contains hidden or 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
const apiInitPause = 100 * time.Millisecond // delay between api calls to avoid triggering API flood protection | |
const apiInitMult = 3 // magnitude of spread between random min-max calls to client init calls | |
const apiUrl = "https://api.com/token=123456759" | |
func initClients(ctx context.Context, tickers []string, events []chan *sse.Event) { | |
rand.Seed(time.Now().UTC().UnixNano()) | |
for _, v := range tickers { | |
apiInitPause := randInt(apiInitPause/apiInitMult, apiInitPause*apiInitMult) | |
time.Sleep(apiInitPause) | |
go startClient(ctx, fmt.Sprintf("%s/trades=%s", apiUrl, v), events[0]) | |
time.Sleep(apiInitPause) | |
go startClient(ctx, fmt.Sprintf("%s/security=%s", apiUrl, v), events[1]) | |
time.Sleep(apiInitPause) | |
go startClient(ctx, fmt.Sprintf("%s/auctions=%s", apiUrl, v), events[2]) | |
} | |
} | |
func startClient(ctx context.Context, url string, ch chan *sse.Event) { | |
log.Println("Client started", url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment