@azure/app-configuration
Version:
An isomorphic client library for the Azure App Configuration service.
62 lines • 2.21 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Wraps a v3 core-lro `PollerLike` so that it exposes the v2-style `SimplePollerLike` API
* surface expected by existing callers of `@azure/app-configuration`.
*
* @internal
*/
export async function wrapPoller(httpPoller) {
const abortController = new AbortController();
const simplePoller = {
isDone() {
return httpPoller.isDone;
},
isStopped() {
return abortController.signal.aborted;
},
getOperationState() {
if (!httpPoller.operationState) {
throw new Error("Operation state is not available. The poller may not have been started; await submitted() before calling getOperationState().");
}
return httpPoller.operationState;
},
getResult() {
return httpPoller.result;
},
toString() {
if (!httpPoller.operationState) {
throw new Error("Operation state is not available. The poller may not have been started; await submitted() before calling getOperationState().");
}
return JSON.stringify({
state: httpPoller.operationState,
});
},
stopPolling() {
abortController.abort();
},
onProgress: httpPoller.onProgress,
async poll(options) {
await httpPoller.poll(options);
},
pollUntilDone(pollOptions) {
function abortListener() {
abortController.abort();
}
const inputAbortSignal = pollOptions?.abortSignal;
const abortSignal = abortController.signal;
if (inputAbortSignal?.aborted) {
abortController.abort();
}
else if (!abortSignal.aborted) {
inputAbortSignal?.addEventListener("abort", abortListener, {
once: true,
});
}
return httpPoller.pollUntilDone({ abortSignal: abortController.signal });
},
};
await httpPoller.submitted();
return simplePoller;
}
//# sourceMappingURL=lroShim.js.map