UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

36 lines (34 loc) 1.14 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.createAbortableTask = createAbortableTask; function createAbortableTask(executor) { const abortController = new AbortController(); let state = 'IN_PROGRESS'; const resultPromise = executor(abortController); const wrappedPromise = resultPromise .then(result => { state = 'SUCCESS'; return result; }) .catch(error => { state = abortController.signal.aborted ? 'CANCELED' : 'ERROR'; throw error; }); const operation = { result: wrappedPromise, cancel: () => { abortController.abort(); state = 'CANCELED'; }, get state() { return state; }, then: wrappedPromise.then.bind(wrappedPromise), catch: wrappedPromise.catch.bind(wrappedPromise), finally: wrappedPromise.finally.bind(wrappedPromise), }; return operation; } //# sourceMappingURL=createAbortableTask.js.map