Source: RequestMulti.js

  1. const Request = require('./Request')
  2. /**
  3. * A request consisting of several requests - duplicate results will be filtered
  4. * @extends Request
  5. */
  6. class RequestMulti extends Request {
  7. constructor (overpass, options, requests) {
  8. super(overpass, options)
  9. this.type = 'RequestMulti'
  10. this.doneFeatures = {}
  11. this.requests = requests
  12. this.requests.forEach(req => {
  13. req.on('finish', () => {
  14. this.requests.splice(this.requests.indexOf(req), 1)
  15. })
  16. req.on('subrequest-compile', (subRequest) => this.emit('subrequest-compile', subRequest))
  17. req.on('subrequest-finish', (subRequest) => this.emit('subrequest-finish', subRequest))
  18. req.featureCallback = (err, ob) => {
  19. if (!(ob.id in this.doneFeatures)) {
  20. this.doneFeatures[ob.id] = true
  21. this.featureCallback(err, ob)
  22. }
  23. }
  24. req.finalCallback = () => {}
  25. this.overpass.requests.push(req)
  26. })
  27. }
  28. /**
  29. * abort this request and sub requests
  30. */
  31. abort () {
  32. this.requests.forEach(req => req.abort())
  33. super.abort()
  34. }
  35. willInclude () {
  36. return false
  37. }
  38. preprocess () {
  39. }
  40. mayFinish () {
  41. return !this.requests.length
  42. }
  43. }
  44. module.exports = RequestMulti