-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Standardization of our documentation comments #12912
Changes from 22 commits
7d3107c
65480b6
e1dfdfa
76352ca
7a1f774
bbbb801
e9616d3
29ceb4a
f8cee2a
ffb4336
7fe51c4
a6d015c
365d315
8e21687
463b5e9
0669122
a940843
bf40c44
3197ed1
5084c10
37ce528
ec0b33c
f3c3c94
8a471bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal"; | |
* error matches `"AbortError"`. | ||
* | ||
* @example | ||
* ```ts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Lets make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. This is for just highlighting though and I think color scheme should be the same for both languages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the color scheme would be same. My reason to call this out was to avoid someone in the future looking at this and trying to add TypeScript code |
||
* const controller = new AbortController(); | ||
* controller.abort(); | ||
* try { | ||
|
@@ -18,6 +19,7 @@ import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal"; | |
* // handle abort error here. | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export class AbortError extends Error { | ||
constructor(message?: string) { | ||
|
@@ -31,44 +33,44 @@ export class AbortError extends Error { | |
* that an asynchronous operation should be aborted. | ||
* | ||
* @example | ||
* // Abort an operation when another event fires | ||
* Abort an operation when another event fires | ||
* ```ts | ||
* const controller = new AbortController(); | ||
* const signal = controller.signal; | ||
* doAsyncWork(signal); | ||
* button.addEventListener('click', () => controller.abort()); | ||
* ``` | ||
* | ||
* @example | ||
* // Share aborter cross multiple operations in 30s | ||
* Share aborter cross multiple operations in 30s | ||
* ```ts | ||
* // Upload the same data to 2 different data centers at the same time, | ||
* // abort another when any of them is finished | ||
* const controller = AbortController.withTimeout(30 * 1000); | ||
* doAsyncWork(controller.signal).then(controller.abort); | ||
* doAsyncWork(controller.signal).then(controller.abort); | ||
*``` | ||
* | ||
* @example | ||
* // Cascaded aborting | ||
* Cascaded aborting | ||
* ```ts | ||
* // All operations can't take more than 30 seconds | ||
* const aborter = Aborter.timeout(30 * 1000); | ||
* | ||
* // Following 2 operations can't take more than 25 seconds | ||
* await doAsyncWork(aborter.withTimeout(25 * 1000)); | ||
* await doAsyncWork(aborter.withTimeout(25 * 1000)); | ||
* | ||
* @export | ||
* @class AbortController | ||
* @implements {AbortSignalLike} | ||
* ``` | ||
*/ | ||
export class AbortController { | ||
private _signal: AbortSignal; | ||
|
||
/** | ||
* @param {AbortSignalLike[]} [parentSignals] The AbortSignals that will signal aborted on the AbortSignal associated with this controller. | ||
* @constructor | ||
* @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller. | ||
*/ | ||
constructor(parentSignals?: AbortSignalLike[]); | ||
/** | ||
* @param {...AbortSignalLike} parentSignals The AbortSignals that will signal aborted on the AbortSignal associated with this controller. | ||
* @constructor | ||
* @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller. | ||
*/ | ||
constructor(...parentSignals: AbortSignalLike[]); | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
|
@@ -102,8 +104,6 @@ export class AbortController { | |
* when the abort method is called on this controller. | ||
* | ||
* @readonly | ||
* @type {AbortSignal} | ||
* @memberof AbortController | ||
*/ | ||
public get signal(): AbortSignal { | ||
return this._signal; | ||
|
@@ -112,19 +112,14 @@ export class AbortController { | |
/** | ||
* Signal that any operations passed this controller's associated abort signal | ||
* to cancel any remaining work and throw an `AbortError`. | ||
* | ||
* @memberof AbortController | ||
*/ | ||
abort(): void { | ||
abortSignal(this._signal); | ||
} | ||
|
||
/** | ||
* Creates a new AbortSignal instance that will abort after the provided ms. | ||
* | ||
* @static | ||
* @params {number} ms Elapsed time in milliseconds to trigger an abort. | ||
* @returns {AbortSignal} | ||
* @param ms - Elapsed time in milliseconds to trigger an abort. | ||
*/ | ||
public static timeout(ms: number): AbortSignal { | ||
const signal = new AbortSignal(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for another time, not for this PR: Check if
@example
tag is still valid in the latest typedoc tool. I recall that the docs at docs.microsoft.com/javascript/api simply ignore this tag and anything that comes after it based on our experience. cc @HarshaNalluru and @willmtemple for confirmationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeDoc plans to have full support for TSDoc in the upcoming year. Until then, we can perhaps use the following plugin: https://github.com/ardalanamini/typedoc-plugin-example-tag.