blob: e8e384e89b513005206cf335b120eb2312df8c06 (
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
|
/**
* @fileoverview Group requests together and then abort as a group.
*
* var sandbox = new dav.Sandbox();
* return Promise.all([
* dav.createEvent(event, { sandbox: sandbox }),
* dav.deleteEvent(other, { sandbox: sandbox })
* ])
* .catch(function() {
* // Something went wrong so abort all requests.
* sandbox.abort;
* });
*/
let debug = require('./debug')('dav:sandbox');
export class Sandbox {
constructor() {
this.requestList = [];
}
add(request) {
debug('Adding request to sandbox.');
this.requestList.push(request);
}
abort() {
debug('Aborting sandboxed requests.');
this.requestList.forEach(request => request.abort());
}
}
export function createSandbox() {
return new Sandbox();
}
|