diff options
Diffstat (limited to 'js/dav/lib/sandbox.js')
-rw-r--r-- | js/dav/lib/sandbox.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/js/dav/lib/sandbox.js b/js/dav/lib/sandbox.js new file mode 100644 index 00000000..e8e384e8 --- /dev/null +++ b/js/dav/lib/sandbox.js @@ -0,0 +1,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(); +} |