From 39fd53502903b2f08c2e06bd2250f48f2bcf247a Mon Sep 17 00:00:00 2001 From: Mikhail Gorkovenko <57451566+misbiheyv@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:52:06 +1000 Subject: [PATCH] docs: better description (#431) --- src/core/promise/abortable/index.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/promise/abortable/index.ts b/src/core/promise/abortable/index.ts index b2109aef7..22f3a07bf 100644 --- a/src/core/promise/abortable/index.ts +++ b/src/core/promise/abortable/index.ts @@ -611,8 +611,28 @@ export default class AbortablePromise implements Promise { } /** - * Aborts the current promise (the promise will be rejected) - * @param [reason] - abort reason + * Aborts the current promise. + * The promise will be rejected only if it doesn't have any active consumers. + * You can follow the link to see how to get around this behavior. + * @see https://github.com/V4Fire/Core/blob/a0635b1ed2600409b5c14b5f85f0281a4f48ee8c/src/core/promise/abortable/README.md#tied-promises + * + * @param [reason] + * + * @example + * ```js + * const promise1 = new AbortablePromise(...); + * const promise2 = new AbortablePromise(...); + * + * promise1.then((res) => doSomething(res)); + * promise2.then((res) => doSomething(res)); + * promise2.then((res) => doSomethingElse(res)); + * + * // It will be aborted, because it has only 1 consumer + * promise1.abort(); + * + * // It won't be aborted, because it has 2 consumers + * promise2.abort(); + * ``` */ abort(reason?: unknown): boolean { if (!this.isPending || this.aborted || Object.get(reason, [IGNORE]) === true) {