1 | var Communication = require('./communication')
|
2 | var communicate = new Communication()
|
3 |
|
4 | var 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 |
|
22 | module.exports = requestQueue |
\ | No newline at end of file |