Skip to content

Commit f169f9e

Browse files
authored
[notification-hubs] Moving to core-lro v3 (#31002)
### Packages impacted by this PR - @azure/notification-hubs ### Issues associated with this PR ### Describe the problem that is addressed by this PR Moves @azure/notification-hubs to @azure/core-lro v3 ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent c34e215 commit f169f9e

File tree

7 files changed

+51
-29
lines changed

7 files changed

+51
-29
lines changed

sdk/notificationhubs/notification-hubs/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Release History
22

3-
## 1.2.4 (Unreleased)
3+
## 2.0.0 (Unreleased)
44

55
### Features Added
66

7+
- Moved to `@azure/core-lro` v3 for long running operations.
8+
79
### Breaking Changes
810

11+
- Moving from `@azure/core-lro` v2 to v3 for long running operations. For APIs such as `beginSubmitNotificationHubJob`, this is a breaking change as it uses the new `PollerLike` interface instead of the old `SimplePollerLike` interface. See the [Polling API](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/docs/MIGRATION.md#poller-api) migration guide for more information.
12+
913
### Bugs Fixed
1014

1115
- Added `pushChannelExpired` and `pushVariables` to the `Installation` type.

sdk/notificationhubs/notification-hubs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/notification-hubs",
3-
"version": "1.2.4",
3+
"version": "2.0.0",
44
"description": "Azure Notification Hubs SDK for JavaScript",
55
"sdk-type": "client",
66
"main": "./dist/commonjs/index.js",
@@ -80,7 +80,7 @@
8080
"dependencies": {
8181
"@azure/core-auth": "^1.7.2",
8282
"@azure/abort-controller": "^2.1.2",
83-
"@azure/core-lro": "^2.7.2",
83+
"@azure/core-lro": "^3.0.0",
8484
"@azure/core-paging": "^1.6.2",
8585
"@azure/core-rest-pipeline": "^1.15.2",
8686
"@azure/core-tracing": "^1.1.2",

sdk/notificationhubs/notification-hubs/review/notification-hubs-api.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { OperationState } from '@azure/core-lro';
1111
import { PagedAsyncIterableIterator } from '@azure/core-paging';
1212
import { PipelineRequest } from '@azure/core-rest-pipeline';
1313
import { PipelineResponse } from '@azure/core-rest-pipeline';
14-
import { SimplePollerLike } from '@azure/core-lro';
14+
import { PollerLike } from '@azure/core-lro';
1515

1616
// @public
1717
export function beginSubmitNotificationHubJob(context: NotificationHubsClientContext, notificationHubJob: NotificationHubJob, polledOperationOptions?: PolledOperationOptions): Promise<NotificationHubJobPoller>;

sdk/notificationhubs/notification-hubs/review/notification-hubs-models.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { ClientOptions } from '@azure-rest/core-client';
88
import { OperationOptions } from '@azure-rest/core-client';
99
import { OperationState } from '@azure/core-lro';
10-
import { SimplePollerLike } from '@azure/core-lro';
10+
import { PollerLike } from '@azure/core-lro';
1111

1212
// @public
1313
export interface AdmInstallation extends DeviceTokenInstallation {
@@ -835,7 +835,7 @@ export interface NotificationHubJob {
835835
}
836836

837837
// @public
838-
export type NotificationHubJobPoller = SimplePollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
838+
export type NotificationHubJobPoller = PollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
839839

840840
// @public
841841
export type NotificationHubJobStatus =

sdk/notificationhubs/notification-hubs/review/notification-hubs.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ClientOptions } from '@azure-rest/core-client';
88
import { OperationOptions } from '@azure-rest/core-client';
99
import { OperationState } from '@azure/core-lro';
1010
import { PagedAsyncIterableIterator } from '@azure/core-paging';
11-
import { SimplePollerLike } from '@azure/core-lro';
11+
import { PollerLike } from '@azure/core-lro';
1212

1313
// @public
1414
export interface AdmInstallation extends DeviceTokenInstallation {
@@ -836,7 +836,7 @@ export interface NotificationHubJob {
836836
}
837837

838838
// @public
839-
export type NotificationHubJobPoller = SimplePollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
839+
export type NotificationHubJobPoller = PollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
840840

841841
// @public
842842
export type NotificationHubJobStatus =

sdk/notificationhubs/notification-hubs/src/api/beginSubmitNotificationHubJob.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { AbortSignalLike } from "@azure/abort-controller";
5-
import { CancelOnProgress, OperationState, SimplePollerLike } from "@azure/core-lro";
5+
import { CancelOnProgress, OperationState, PollerLike } from "@azure/core-lro";
66
import { NotificationHubJob, NotificationHubJobPoller } from "../models/notificationHubJob.js";
77
import { NotificationHubsClientContext } from "./index.js";
88
import { PolledOperationOptions } from "../models/options.js";
@@ -38,12 +38,13 @@ export async function beginSubmitNotificationHubJob(
3838
const processProgressCallbacks = async (): Promise<void> =>
3939
progressCallbacks.forEach((h) => h(state));
4040
let resultPromise: Promise<NotificationHubJob> | undefined;
41-
let cancelJob: (() => void) | undefined;
4241
const abortController = new AbortController();
4342
const currentPollIntervalInMs = polledOperationOptions.updateIntervalInMs ?? 2000;
4443

45-
const poller: SimplePollerLike<OperationState<NotificationHubJob>, NotificationHubJob> = {
46-
async poll(options?: { abortSignal?: AbortSignalLike }): Promise<void> {
44+
const poller: PollerLike<OperationState<NotificationHubJob>, NotificationHubJob> = {
45+
async poll(options?: {
46+
abortSignal?: AbortSignalLike;
47+
}): Promise<OperationState<NotificationHubJob>> {
4748
submittedJob = await getNotificationHubJob(context, submittedJob.jobId!, options);
4849
if (submittedJob.status === "Running" || submittedJob.status === "Started") {
4950
state.status = "running";
@@ -67,6 +68,8 @@ export async function beginSubmitNotificationHubJob(
6768
if (state.status === "failed") {
6869
throw state.error;
6970
}
71+
72+
return state;
7073
},
7174

7275
pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<NotificationHubJob> {
@@ -84,9 +87,9 @@ export async function beginSubmitNotificationHubJob(
8487
}
8588

8689
try {
87-
if (!poller.isDone()) {
90+
if (!poller.isDone) {
8891
await poller.poll({ abortSignal });
89-
while (!poller.isDone()) {
92+
while (!poller.isDone) {
9093
await delay(currentPollIntervalInMs, { abortSignal });
9194
await poller.poll({ abortSignal });
9295
}
@@ -96,7 +99,7 @@ export async function beginSubmitNotificationHubJob(
9699
}
97100
switch (state.status) {
98101
case "succeeded":
99-
return poller.getResult() as NotificationHubJob;
102+
return poller.result as NotificationHubJob;
100103
case "canceled":
101104
throw new Error("Operation was canceled");
102105
case "failed":
@@ -117,30 +120,45 @@ export async function beginSubmitNotificationHubJob(
117120
return () => progressCallbacks.delete(s);
118121
},
119122

120-
isDone(): boolean {
123+
get isDone(): boolean {
121124
return ["succeeded", "failed", "canceled"].includes(state.status);
122125
},
123126

124-
stopPolling(): void {
125-
abortController.abort();
126-
cancelJob?.();
127+
get operationState(): OperationState<NotificationHubJob> | undefined {
128+
return state;
127129
},
128130

129-
isStopped(): boolean {
130-
return resultPromise === undefined;
131+
get result(): NotificationHubJob | undefined {
132+
return state.result;
131133
},
132134

133-
getOperationState(): OperationState<NotificationHubJob> {
134-
return state;
135+
async serialize(): Promise<string> {
136+
return JSON.stringify({ state });
135137
},
136138

137-
getResult(): NotificationHubJob | undefined {
138-
return state.result;
139+
async submitted() {
140+
// No-op
141+
return;
139142
},
140143

141-
toString() {
142-
return JSON.stringify({ state });
144+
then<TResult1 = NotificationHubJob, TResult2 = never>(
145+
onfulfilled?:
146+
| ((value: NotificationHubJob) => TResult1 | PromiseLike<TResult1>)
147+
| undefined
148+
| null,
149+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
150+
): Promise<TResult1 | TResult2> {
151+
return poller.pollUntilDone().then(onfulfilled, onrejected);
152+
},
153+
catch<TResult2 = never>(
154+
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
155+
): Promise<NotificationHubJob | TResult2> {
156+
return poller.pollUntilDone().catch(onrejected);
157+
},
158+
finally(onfinally?: (() => void) | undefined | null): Promise<NotificationHubJob> {
159+
return poller.pollUntilDone().finally(onfinally);
143160
},
161+
[Symbol.toStringTag]: "Poller",
144162
};
145163

146164
return poller;

sdk/notificationhubs/notification-hubs/src/models/notificationHubJob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { OperationState, SimplePollerLike } from "@azure/core-lro";
4+
import { OperationState, PollerLike } from "@azure/core-lro";
55

66
/**
77
* Describes the types of notification hub jobs.
@@ -131,7 +131,7 @@ export interface NotificationHubJob {
131131
/**
132132
* Describes a poller for NotificationHubJob types.
133133
*/
134-
export type NotificationHubJobPoller = SimplePollerLike<
134+
export type NotificationHubJobPoller = PollerLike<
135135
OperationState<NotificationHubJob>,
136136
NotificationHubJob
137137
>;

0 commit comments

Comments
 (0)