Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GA core-lro v3 #29450

Merged
merged 9 commits into from May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions sdk/core/core-lro/CHANGELOG.md
@@ -1,14 +1,9 @@
# Release History

## 3.0.0-beta.3 (Unreleased)
## 3.0.0 (Unreleased)

### Features Added

### Breaking Changes
GA the v3 version. To migrate the existing applications to v3, please refer to [Migration Guide](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-lro/docs/MIGRATION.md).

### Bugs Fixed

### Other Changes

## 3.0.0-beta.2 (2024-04-26)

Expand Down
137 changes: 137 additions & 0 deletions sdk/core/core-lro/docs/MIGRATION.md
Expand Up @@ -92,3 +92,140 @@ now
```ts
const serializeState = await poller.serialize();
```

## `core-lro-shim`

There are situations where we don't want to break existing code and want to keep backward compatibility. Here we prepare `core-lro-shim` scripts for you, in which we implemented v2 `SimplePollerLike` interfaces with v3 interfaces.

Once you copy them into your environment and the only thing you need to do is to update your lro references to that shim.

```ts
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { AbortSignalLike } from "@azure/abort-controller";
import {
CancelOnProgress,
CreateHttpPollerOptions,
OperationState,
RunningOperation,
createHttpPoller as createInternalHttpPoller,
} from "@azure/core-lro";

/**
* A simple poller that can be used to poll a long running operation.
*/
export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {
/**
* Returns true if the poller has finished polling.
*/
isDone(): boolean;
/**
* Returns true if the poller is stopped.
*/
isStopped(): boolean;
/**
* Returns the state of the operation.
*/
getOperationState(): TState;
/**
* Returns the result value of the operation,
* regardless of the state of the poller.
* It can return undefined or an incomplete form of the final TResult value
* depending on the implementation.
*/
getResult(): TResult | undefined;
/**
* Returns a promise that will resolve once a single polling request finishes.
* It does this by calling the update method of the Poller's operation.
*/
poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;
/**
* Returns a promise that will resolve once the underlying operation is completed.
*/
pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;
/**
* Invokes the provided callback after each polling is completed,
* sending the current state of the poller's operation.
*
* It returns a method that can be used to stop receiving updates on the given callback function.
*/
onProgress(callback: (state: TState) => void): CancelOnProgress;

/**
* Wait the poller to be submitted.
*/
submitted(): Promise<void>;

/**
* Returns a string representation of the poller's operation. Similar to serialize but returns a string.
*/
toString(): string;

/**
* Stops the poller from continuing to poll. Please note this will only stop the client-side polling
*/
stopPolling(): void;
}

export async function createHttpPoller<TResult, TState extends OperationState<TResult>>(
lro: RunningOperation,
options?: CreateHttpPollerOptions<TResult, TState>,
): Promise<SimplePollerLike<TState, TResult>> {
const httpPoller = createInternalHttpPoller(lro, options);
const abortController = new AbortController();
const simplePoller: SimplePollerLike<TState, TResult> = {
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 and you could 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 and you could await submitted() before calling getOperationState().",
);
}
return JSON.stringify({
state: httpPoller.operationState,
});
},
stopPolling() {
abortController.abort();
},
onProgress: httpPoller.onProgress,
poll: httpPoller.poll,
pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }) {
function abortListener(): void {
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 });
},
submitted: httpPoller.submitted,
};
await httpPoller.submitted();
return simplePoller;
}

```
2 changes: 1 addition & 1 deletion sdk/core/core-lro/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@azure/core-lro",
"author": "Microsoft Corporation",
"sdk-type": "client",
"version": "3.0.0-beta.3",
"version": "3.0.0",
"type": "module",
"description": "Isomorphic client library for supporting long-running operations in node.js and browser.",
"exports": {
Expand Down