MCPcopy Create free account
hub / github.com/microsoft/vscode-cpptools / ManualSignal

Class ManualSignal

Extension/src/Utility/Async/manualSignal.ts:17–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 * of managinng a subscription to an event emitter.
16 */
17export class ManualSignal<T> implements Promise<T>, Resetable<T> {
18 [Symbol.toStringTag] = 'Promise';
19
20 private promise = new ManualPromise<T>();
21 constructor(initiallyReset = false) {
22 if (!initiallyReset) {
23 // initially not reset.
24 this.promise.resolve();
25 }
26 }
27 get isPending(): boolean {
28 return this.promise.isPending;
29 }
30 get isCompleted(): boolean {
31 return this.promise.isCompleted;
32 }
33 get isResolved(): boolean {
34 return this.promise.isResolved;
35 }
36 get isRejected(): boolean {
37 return this.promise.isRejected;
38 }
39 get isSet(): boolean {
40 return this.promise.isCompleted;
41 }
42 get isReset(): boolean {
43 return !this.promise.isCompleted;
44 }
45 /**
46 * Attaches callbacks for the resolution and/or rejection of the Promise.
47 * @param onfulfilled The callback to execute when the Promise is resolved.
48 * @param onrejected The callback to execute when the Promise is rejected.
49 * @returns A Promise for the completion of which ever callback is executed.
50 */
51 then<TResult1 = T, TResult2 = never>(onfulfilled?: | ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: | ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2> {
52 return this.promise.then(onfulfilled, onrejected);
53 }
54
55 /**
56 * Attaches a callback for only the rejection of the Promise.
57 * @param onrejected The callback to execute when the Promise is rejected.
58 * @returns A Promise for the completion of the callback.
59 */
60 catch<TResult = never>(onrejected?: | ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult> {
61 return this.promise.catch(onrejected);
62 }
63
64 /**
65 * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
66 * resolved value cannot be modified from the callback.
67 * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
68 * @returns A Promise for the completion of the callback.
69 */
70 finally(onfinally?: (() => void) | null | undefined): Promise<T> {
71 return this.promise.finally(onfinally);
72 }
73
74 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected