UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

34 lines (32 loc) 1.04 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 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; } export { createAbortableTask }; //# sourceMappingURL=createAbortableTask.mjs.map