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
| // Paste the code below into your webbrowser console and press "enter" | |
| // To open the console you can press "F12" or "Ctrl + Shift + J" for most browsers. | |
| // Read more here: https://appuals.com/open-browser-console/ | |
| // Instructions video on my twitter: https://twitter.com/_carlhannes/status/1590441813445599232 | |
| // The code re-tries fetching data if it gets status 429, which is the error that the SJ page has | |
| // It does this together with an exponential back-off delay which is common to use with microservices of this type | |
| // Because of these re-tries and the delay, the overall load of the website and the servers will be lower, | |
| // since it does not need to re-fetch requests that actually succeed. Read more on my twitter if you're interested: | |
| // https://twitter.com/_carlhannes/status/1590605735314206721 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
| <link rel="stylesheet" href="/css/mobile.css" /> |
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
| /* | |
| Parallel processing with ordered output in Go | |
| (you can use this pattern by importing https://github.com/MarianoGappa/parseq) | |
| This example implementation is useful when the following 3 conditions are true: | |
| 1) the rate of input is higher than the rate of output on the system (i.e. it queues up) | |
| 2) the processing of input can be parallelised, and overall throughput increases by doing so | |
| 3) the order of output of the system needs to respect order of input | |
| - if 1 is false, KISS! |
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
| /* | |
| This snippet is an example of backpressure implementation in Go. | |
| It doesn't run in Go Playground, because it starts an HTTP Server. | |
| The example starts an HTTP server and sends multiple requests to it. The server starts denying | |
| requests by replying an "X" (i.e. a 502) when its buffered channel reaches capacity. | |
| This is not the same as rate-limiting; you might be interested in https://github.com/juju/ratelimit | |
| or https://godoc.org/golang.org/x/time/rate. |