Update progress example
This commit is contained in:
parent
eb6707644f
commit
694645cd40
@ -11,18 +11,17 @@ uv_async_t async;
|
||||
_Atomic double percentage;
|
||||
|
||||
void fake_download(uv_work_t *req) {
|
||||
int size = *((int *)req->data);
|
||||
int downloaded = 0;
|
||||
double pct;
|
||||
while (downloaded < size) {
|
||||
pct = downloaded * 100.0 / size;
|
||||
atomic_store_explicit(&percentage, pct, memory_order_release);
|
||||
uv_async_send(&async);
|
||||
int size = *((int*) req->data);
|
||||
int downloaded = 0;
|
||||
while (downloaded < size) {
|
||||
pct = downloaded * 100.0 / size;
|
||||
atomic_store_explicit(&percentage, pct, memory_order_release);
|
||||
uv_async_send(&async);
|
||||
|
||||
sleep(1);
|
||||
downloaded += (200 + random()) % 1000; // can only download max
|
||||
// 1000bytes/sec, but at least a 200;
|
||||
}
|
||||
sleep(1);
|
||||
downloaded += (200+random())%1000; // can only download max 1000bytes/sec,
|
||||
// but at least a 200;
|
||||
}
|
||||
}
|
||||
|
||||
void after(uv_work_t *req, int status) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user