Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Minimal async HTTP | cf46dcf53f92355652046732b049d66f78170151 | terorie | 2018-07-30 01:09:23 |
Multithreading proof-of-concept | 593c61acca56f9bebbdb8ded27d98c7c016d7d8e | terorie | 2018-07-30 01:04:14 |
Fix CLI for channel dumps | e2ea0a179ea584fa994a05dc913298c904060412 | terorie | 2018-07-29 22:10:50 |
Move work command | fec4a5e0677f2f72a87db79fd673aab17c776241 | terorie | 2018-07-29 21:56:21 |
Set API by CLI | a9589194e7b5cbd33d5cf0fc96d71334d094520a | terorie | 2018-07-29 21:53:47 |
include GPLv3 | e9b14041d4ecc991f1c40ecff4e13b737b1ccc15 | terorie | 2018-07-29 21:34:50 |
Refactor API selection | c3b6047f98184e618ceb88965583e2aabe71fb7d | terorie | 2018-07-29 21:34:19 |
Channel url dump CLI | 0429c2f1ceef84d2e7505591a0fee9babce7eb52 | terorie | 2018-07-29 02:09:59 |
Cobra & channel video dumper | b6a0e418403b24df1162b749878d24a9918f9b8c | terorie | 2018-07-28 23:49:38 |
Rename project to yt-mango | 0f19dcfd3f54c3902a0aa97b8c0f4aa932538d73 | terorie | 2018-07-28 15:10:49 |
Remove debug output | 9f5b9dd87324b30044723539875ee8a419b7eee0 | terorie | 2018-07-28 14:45:13 |
Decode video formats | bafc6c4ad3587e2de7a88cf532ad1df5ee5a7964 | terorie | 2018-07-28 14:34:57 |
Add formats from youtube-dl | e612768d79ed1743b415073d9dba713e785e2ea6 | terorie | 2018-07-28 13:33:48 |
Initial README | 0e9d46ecadcc5b019b9fae4e356bc3360f521b5e | terorie | 2018-07-28 03:56:26 |
Initial commit | 3b5744c589494163e05a9d54fba10c71e5965d6a | terorie | 2018-07-28 03:55:53 |
File | Lines added | Lines deleted |
---|---|---|
common/httpasync.go | 35 | 0 |
File common/httpasync.go added (mode: 100644) (index 0000000..5dbf097) | |||
1 | package common | ||
2 | |||
3 | import "net/http" | ||
4 | |||
5 | type JobResult struct { | ||
6 | Res *http.Response | ||
7 | Err error | ||
8 | ReqData interface{} // job.data | ||
9 | } | ||
10 | |||
11 | type job struct { | ||
12 | req *http.Request | ||
13 | c chan JobResult | ||
14 | data interface{} | ||
15 | } | ||
16 | |||
17 | var jobs = make(chan job) | ||
18 | |||
19 | func InitAsyncHTTP(nWorkers uint) { | ||
20 | for i := uint(0); i < nWorkers; i++ { | ||
21 | go asyncHTTPWorker() | ||
22 | } | ||
23 | } | ||
24 | |||
25 | func DoAsyncHTTP(r *http.Request, c chan JobResult, data interface{}) { | ||
26 | jobs <- job{r, c, data} | ||
27 | } | ||
28 | |||
29 | func asyncHTTPWorker() { | ||
30 | for { | ||
31 | job := <-jobs | ||
32 | res, err := Client.Do(job.req) | ||
33 | job.c <- JobResult{res, err, job.data} | ||
34 | } | ||
35 | } |