forked from plepe/overpass-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequestMulti.js
55 lines (44 loc) · 1.21 KB
/
RequestMulti.js
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
50
51
52
53
54
55
const Request = require('./Request')
/**
* A request consisting of several requests - duplicate results will be filtered
* @extends Request
*/
class RequestMulti extends Request {
constructor (overpass, options, requests) {
super(overpass, options)
this.type = 'RequestMulti'
this.doneFeatures = {}
this.requests = requests
this.requests.forEach(req => {
req.on('finish', () => {
this.requests.splice(this.requests.indexOf(req), 1)
})
req.on('subrequest-compile', (subRequest) => this.emit('subrequest-compile', subRequest))
req.on('subrequest-finish', (subRequest) => this.emit('subrequest-finish', subRequest))
req.featureCallback = (err, ob) => {
if (!(ob.id in this.doneFeatures)) {
this.doneFeatures[ob.id] = true
this.featureCallback(err, ob)
}
}
req.finalCallback = () => {}
this.overpass.requests.push(req)
})
}
/**
* abort this request and sub requests
*/
abort () {
this.requests.forEach(req => req.abort())
super.abort()
}
willInclude () {
return false
}
preprocess () {
}
mayFinish () {
return !this.requests.length
}
}
module.exports = RequestMulti