blob: 39fbd367893e6a257509e861e8ab21a22a05f393 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <mbgl/storage/request.hpp>
#include <mbgl/storage/base_request.hpp>
#include <uv.h>
#include <cassert>
namespace mbgl {
Request::Request(const util::ptr<BaseRequest> &base_)
: thread_id(std::this_thread::get_id()), base(base_) {
}
Request::~Request() {
assert(thread_id == std::this_thread::get_id());
}
void Request::onload(CompletedCallback cb) {
assert(thread_id == std::this_thread::get_id());
if (base) {
Callback *callback = base->add(std::move(cb), base);
if (callback) {
callbacks.push_front(callback);
}
}
}
void Request::oncancel(AbortedCallback cb) {
assert(thread_id == std::this_thread::get_id());
if (base) {
Callback *callback = base->add(std::move(cb), base);
if (callback) {
callbacks.push_front(callback);
}
}
}
void Request::cancel() {
assert(thread_id == std::this_thread::get_id());
if (base) {
for (Callback *callback : callbacks) {
base->remove(callback);
}
base.reset();
}
callbacks.clear();
}
}
|