Skip to content

Commit 30bb2f7

Browse files
chore: remove unused CancellablePromise and gracefullyCancel utilities
1 parent cfacb39 commit 30bb2f7

2 files changed

Lines changed: 1 addition & 115 deletions

File tree

agents/etc/agents.api.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,29 +1985,6 @@ export function calculateAudioDurationSeconds(frame: AudioBuffer_2): number;
19851985
// @public (undocumented)
19861986
export function cancelAndWait(tasks: Task<any>[], timeout?: number): Promise<void>;
19871987

1988-
// Warning: (ae-internal-missing-underscore) The name "CancellablePromise" should be prefixed with an underscore because the declaration is marked as @internal
1989-
//
1990-
// @internal (undocumented)
1991-
export class CancellablePromise<T, E extends Error = Error> {
1992-
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason: E) => void, onCancel: (cancelFn: () => void) => void) => void);
1993-
// (undocumented)
1994-
cancel(): void;
1995-
// (undocumented)
1996-
catch<TResult = never>(onrejected?: ((reason: E) => TResult | Promise<TResult>) | null): Promise<Throws<T | TResult | undefined, E>>;
1997-
// (undocumented)
1998-
get error(): Error | null;
1999-
// (undocumented)
2000-
finally(onfinally?: (() => void) | null): Promise<Throws<T, E>>;
2001-
// (undocumented)
2002-
static from<T, E extends Error = Error>(promise: Promise<Throws<T, E>>): CancellablePromise<T, E>;
2003-
// (undocumented)
2004-
static from<T>(promise: Promise<T>): CancellablePromise<T>;
2005-
// (undocumented)
2006-
get isCancelled(): boolean;
2007-
// (undocumented)
2008-
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | Promise<TResult1>) | null, onrejected?: ((reason: E) => TResult2 | Promise<TResult2>) | null): Promise<TResult1 | TResult2>;
2009-
}
2010-
20111988
// Warning: (ae-missing-release-tag) "CartesiaModels" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
20121989
//
20131990
// @public (undocumented)
@@ -3996,12 +3973,6 @@ interface GoogleSTTOptions {
39963973
custom_vocabulary?: string[];
39973974
language_codes?: string[];
39983975
}
3999-
4000-
// Warning: (ae-internal-missing-underscore) The name "gracefullyCancel" should be prefixed with an underscore because the declaration is marked as @internal
4001-
//
4002-
// @internal (undocumented)
4003-
export function gracefullyCancel<T>(promise: CancellablePromise<T>): Promise<void>;
4004-
40053976
// Warning: (ae-missing-release-tag) "handoff" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
40063977
//
40073978
// @public (undocumented)
@@ -9156,7 +9127,7 @@ export const zipFunctionCallsAndOutputs: (event: FunctionToolsExecutedEvent) =>
91569127
// src/metrics/base.ts:194:3 - (ae-forgotten-export) The symbol "RealtimeModelMetricsInputTokenDetails" needs to be exported by the entry point index.d.ts
91579128
// src/metrics/base.ts:198:3 - (ae-forgotten-export) The symbol "RealtimeModelMetricsOutputTokenDetails" needs to be exported by the entry point index.d.ts
91589129
// src/stt/stt.ts:358:3 - (ae-unresolved-link) The @link reference could not be resolved: The package "@livekit/agents" does not have an export "STT"
9159-
// src/utils.ts:501:3 - (ae-unresolved-link) The @link reference could not be resolved: The package "@livekit/agents" does not have an export "cancelled"
9130+
// src/utils.ts:416:3 - (ae-unresolved-link) The @link reference could not be resolved: The package "@livekit/agents" does not have an export "cancelled"
91609131
// src/voice/agent_session.ts:380:3 - (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
91619132
// src/voice/agent_session.ts:988:5 - (ae-forgotten-export) The symbol "RecordingOptions" needs to be exported by the entry point index.d.ts
91629133
// src/voice/agent_session.ts:1626:5 - (ae-forgotten-export) The symbol "STTError" needs to be exported by the entry point index.d.ts

agents/src/utils.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -229,91 +229,6 @@ export class Event {
229229
}
230230
}
231231

232-
/** @internal */
233-
export class CancellablePromise<T, E extends Error = Error> {
234-
#promise: ThrowsPromise<T, E>;
235-
#cancelFn: () => void;
236-
#isCancelled: boolean = false;
237-
#error: E | null = null;
238-
239-
constructor(
240-
executor: (
241-
resolve: (value: T | PromiseLike<T>) => void,
242-
reject: (reason: E) => void,
243-
onCancel: (cancelFn: () => void) => void,
244-
) => void,
245-
) {
246-
let cancel: () => void;
247-
248-
this.#promise = new ThrowsPromise<T, E>((resolve, reject) => {
249-
executor(
250-
resolve,
251-
(reason) => {
252-
this.#error = reason;
253-
reject(reason);
254-
},
255-
(cancelFn) => {
256-
cancel = () => {
257-
this.#isCancelled = true;
258-
cancelFn();
259-
};
260-
},
261-
);
262-
});
263-
264-
this.#cancelFn = cancel!;
265-
}
266-
267-
get isCancelled(): boolean {
268-
return this.#isCancelled;
269-
}
270-
271-
get error(): Error | null {
272-
return this.#error;
273-
}
274-
275-
then<TResult1 = T, TResult2 = never>(
276-
onfulfilled?: ((value: T) => TResult1 | Promise<TResult1>) | null,
277-
onrejected?: ((reason: E) => TResult2 | Promise<TResult2>) | null,
278-
): Promise<TResult1 | TResult2> {
279-
return this.#promise.then(onfulfilled, onrejected);
280-
}
281-
282-
catch<TResult = never>(
283-
onrejected?: ((reason: E) => TResult | Promise<TResult>) | null,
284-
): Promise<Throws<T | TResult | undefined, E>> {
285-
return this.#promise.catch(onrejected);
286-
}
287-
288-
finally(onfinally?: (() => void) | null): Promise<Throws<T, E>> {
289-
return this.#promise.finally(onfinally);
290-
}
291-
292-
cancel(): void {
293-
this.#cancelFn();
294-
}
295-
296-
static from<T, E extends Error = Error>(promise: Promise<Throws<T, E>>): CancellablePromise<T, E>;
297-
static from<T>(promise: Promise<T>): CancellablePromise<T>;
298-
static from<T>(promise: Promise<T>): CancellablePromise<T> {
299-
return new CancellablePromise<T>((resolve, reject) => {
300-
promise.then(resolve).catch(reject);
301-
});
302-
}
303-
}
304-
305-
/** @internal */
306-
export async function gracefullyCancel<T>(promise: CancellablePromise<T>): Promise<void> {
307-
if (!promise.isCancelled) {
308-
promise.cancel();
309-
}
310-
try {
311-
await promise;
312-
} catch (error) {
313-
// Ignore the error, as it's expected due to cancellation
314-
}
315-
}
316-
317232
/** @internal */
318233
export class AsyncIterableQueue<T> implements AsyncIterableIterator<T> {
319234
private static readonly CLOSE_SENTINEL = Symbol('CLOSE_SENTINEL');

0 commit comments

Comments
 (0)