UNPKG

804 BJavaScriptView Raw
1var Communication = require('./communication')
2var communicate = new Communication()
3
4var requestQueue = function() {
5 this.communicate = function(queue) {
6 return new Promise(function(resolve, reject) {
7 var promises = []
8 for (const item of queue) {
9 switch(item.method) {
10 case 'GET': promises.push(communicate.sendGETRequest(item)); break
11 case 'POST': promises.push(communicate.sendPOSTRequest(item)); break
12 default: throw new Error('method must be GET or POST ...')
13 }
14 }
15 Promise.all(promises).then(documents => {
16 resolve(documents)
17 }).catch(err => {reject(err)})
18 })
19 }
20}
21
22module.exports = requestQueue
\No newline at end of file