Skip to content

Commit

Permalink
address poller related feedback - keep only v2 poller and remove the …
Browse files Browse the repository at this point in the history
…backward compat methods/interfaces
  • Loading branch information
HarshaNalluru committed Dec 16, 2024
1 parent 8fe1eba commit 15629cd
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
```ts

import type { AbortSignalLike } from '@azure/abort-controller';
import type { CancelOnProgress } from '@azure/core-lro';
import type { Client } from '@azure-rest/core-client';
import type { ClientOptions } from '@azure-rest/core-client';
import type { CreateHttpPollerOptions } from '@azure/core-lro';
import type { HttpResponse } from '@azure-rest/core-client';
import type { KeyCredential } from '@azure/core-auth';
import type { OperationState } from '@azure/core-lro';
import type { PathUncheckedResponse } from '@azure-rest/core-client';
import type { PollerLike } from '@azure/core-lro';
import type { RawHttpHeaders } from '@azure/core-rest-pipeline';
import type { RawHttpHeadersInput } from '@azure/core-rest-pipeline';
import type { RequestParameters } from '@azure-rest/core-client';
Expand Down Expand Up @@ -1770,28 +1768,34 @@ export interface GetDocumentModelCopyToOperationHeaders {
export type GetDocumentModelCopyToOperationParameters = GetDocumentModelCopyToOperationHeaderParam & RequestParameters;

// @public
export function getLongRunningPoller<TResult extends AnalyzeBatchDocumentsLogicalResponse | AnalyzeBatchDocumentsDefaultResponse>(client: Client, initialResponse: AnalyzeBatchDocuments202Response | AnalyzeBatchDocumentsDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends AnalyzeBatchDocumentsLogicalResponse | AnalyzeBatchDocumentsDefaultResponse>(client: Client, initialResponse: AnalyzeBatchDocuments202Response | AnalyzeBatchDocumentsDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends BuildModelLogicalResponse | BuildModelDefaultResponse>(client: Client, initialResponse: BuildModel202Response | BuildModelDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends BuildModelLogicalResponse | BuildModelDefaultResponse>(client: Client, initialResponse: BuildModel202Response | BuildModelDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends ComposeModelLogicalResponse | ComposeModelDefaultResponse>(client: Client, initialResponse: ComposeModel202Response | ComposeModelDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends ComposeModelLogicalResponse | ComposeModelDefaultResponse>(client: Client, initialResponse: ComposeModel202Response | ComposeModelDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends CopyModelToLogicalResponse | CopyModelToDefaultResponse>(client: Client, initialResponse: CopyModelTo202Response | CopyModelToDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends CopyModelToLogicalResponse | CopyModelToDefaultResponse>(client: Client, initialResponse: CopyModelTo202Response | CopyModelToDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends BuildClassifierLogicalResponse | BuildClassifierDefaultResponse>(client: Client, initialResponse: BuildClassifier202Response | BuildClassifierDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends BuildClassifierLogicalResponse | BuildClassifierDefaultResponse>(client: Client, initialResponse: BuildClassifier202Response | BuildClassifierDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends CopyClassifierToLogicalResponse | CopyClassifierToDefaultResponse>(client: Client, initialResponse: CopyClassifierTo202Response | CopyClassifierToDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends CopyClassifierToLogicalResponse | CopyClassifierToDefaultResponse>(client: Client, initialResponse: CopyClassifierTo202Response | CopyClassifierToDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends AnalyzeDocumentFromStreamLogicalResponse | AnalyzeDocumentFromStreamDefaultResponse>(client: Client, initialResponse: AnalyzeDocumentFromStream202Response | AnalyzeDocumentFromStreamDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends AnalyzeDocumentFromStreamLogicalResponse | AnalyzeDocumentFromStreamDefaultResponse>(client: Client, initialResponse: AnalyzeDocumentFromStream202Response | AnalyzeDocumentFromStreamDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public (undocumented)
export function getLongRunningPoller<TResult extends ClassifyDocumentFromStreamLogicalResponse | ClassifyDocumentFromStreamDefaultResponse>(client: Client, initialResponse: ClassifyDocumentFromStream202Response | ClassifyDocumentFromStreamDefaultResponse, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export function getLongRunningPoller<TResult extends ClassifyDocumentFromStreamLogicalResponse | ClassifyDocumentFromStreamDefaultResponse>(client: Client, initialResponse: ClassifyDocumentFromStream202Response | ClassifyDocumentFromStreamDefaultResponse, options?: GetLongRunningPollerOptions): PollerLike<OperationState<TResult>, TResult>;

// @public
export interface GetLongRunningPollerOptions {
intervalInMs?: number;
restoreFrom?: string;
}

// @public (undocumented)
export interface GetModel {
Expand Down Expand Up @@ -2269,28 +2273,6 @@ export interface Routes {
(path: "/documentClassifiers/{classifierId}:copyTo", classifierId: string): CopyClassifierTo;
}

// @public
export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {
getOperationState(): TState;
getResult(): TResult | undefined;
isDone(): boolean;
// @deprecated
isStopped(): boolean;
onProgress(callback: (state: TState) => void): CancelOnProgress;
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<TState>;
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
serialize(): Promise<string>;
// @deprecated
stopPolling(): void;
submitted(): Promise<void>;
// @deprecated
toString(): string;
}

// @public
export type SplitMode = string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import type { Client, HttpResponse } from "@azure-rest/core-client";
import type { AbortSignalLike } from "@azure/abort-controller";
import type {
CancelOnProgress,
CreateHttpPollerOptions,
RunningOperation,
OperationResponse,
OperationState,
PollerLike,
} from "@azure/core-lro";
import { createHttpPoller } from "@azure/core-lro";
import type {
Expand Down Expand Up @@ -39,69 +38,17 @@ import type {
} from "./responses.js";

/**
* A simple poller that can be used to poll a long running operation.
* Options for `getLongRunningPoller`.
*/
export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {
export interface GetLongRunningPollerOptions {
/**
* Returns true if the poller has finished polling.
* Defines how much time the poller is going to wait before making a new request to the service.
*/
isDone(): boolean;
intervalInMs?: number;
/**
* Returns the state of the operation.
* A serialized poller which can be used to resume an existing paused Long-Running-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;

/**
* Returns a promise that could be used for serialized version of the poller's operation
* by invoking the operation's serialize method.
*/
serialize(): Promise<string>;

/**
* 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.
* @deprecated Use serialize() instead.
*/
toString(): string;

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

/**
* Returns true if the poller is stopped.
* @deprecated Use abortSignal status to track this instead.
*/
isStopped(): boolean;
restoreFrom?: string;
}

/**
Expand All @@ -111,58 +58,58 @@ export interface SimplePollerLike<TState extends OperationState<TResult>, TResul
* @param options - Options to set a resume state or custom polling interval.
* @returns - A poller object to poll for operation state updates and eventually get the final response.
*/
export async function getLongRunningPoller<
export function getLongRunningPoller<
TResult extends AnalyzeBatchDocumentsLogicalResponse | AnalyzeBatchDocumentsDefaultResponse,
>(
client: Client,
initialResponse: AnalyzeBatchDocuments202Response | AnalyzeBatchDocumentsDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends BuildModelLogicalResponse | BuildModelDefaultResponse,
>(
client: Client,
initialResponse: BuildModel202Response | BuildModelDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends ComposeModelLogicalResponse | ComposeModelDefaultResponse,
>(
client: Client,
initialResponse: ComposeModel202Response | ComposeModelDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends CopyModelToLogicalResponse | CopyModelToDefaultResponse,
>(
client: Client,
initialResponse: CopyModelTo202Response | CopyModelToDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends BuildClassifierLogicalResponse | BuildClassifierDefaultResponse,
>(
client: Client,
initialResponse: BuildClassifier202Response | BuildClassifierDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends CopyClassifierToLogicalResponse | CopyClassifierToDefaultResponse,
>(
client: Client,
initialResponse: CopyClassifierTo202Response | CopyClassifierToDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends
| AnalyzeDocumentFromStreamLogicalResponse
| AnalyzeDocumentFromStreamDefaultResponse,
>(
client: Client,
initialResponse: AnalyzeDocumentFromStream202Response | AnalyzeDocumentFromStreamDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<
TResult extends
| ClassifyDocumentFromStreamLogicalResponse
| ClassifyDocumentFromStreamDefaultResponse,
Expand All @@ -171,13 +118,13 @@ export async function getLongRunningPoller<
initialResponse:
| ClassifyDocumentFromStream202Response
| ClassifyDocumentFromStreamDefaultResponse,
options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,
): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;
export async function getLongRunningPoller<TResult extends HttpResponse>(
options?: GetLongRunningPollerOptions,
): PollerLike<OperationState<TResult>, TResult>;
export function getLongRunningPoller<TResult extends HttpResponse>(
client: Client,
initialResponse: TResult,
options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},
): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {
options: GetLongRunningPollerOptions = {},
): PollerLike<OperationState<TResult>, TResult> {
const abortController = new AbortController();
const poller: RunningOperation<TResult> = {
sendInitialRequest: async () => {
Expand Down Expand Up @@ -217,46 +164,7 @@ export async function getLongRunningPoller<TResult extends HttpResponse>(
},
};

options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true;
const httpPoller = createHttpPoller(poller, options);
const simplePoller: SimplePollerLike<OperationState<TResult>, 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: httpPoller.pollUntilDone,
serialize: httpPoller.serialize,
submitted: httpPoller.submitted,
};
return simplePoller;
return createHttpPoller(poller, options);
}

/**
Expand Down
Loading

0 comments on commit 15629cd

Please sign in to comment.