microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-diff-highlight-issue

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/asset-emitter/src/placeholder.ts

18lines · modecode

1/**
2 * Keeps track of a value we don't know yet because of a circular reference. Use
3 * the `onValue` method to provide a callback with how to handle the
4 * placeholder's value becoming available. Generally the callback will replace
5 * this placeholder with the value in whatever references the placeholder.
6 */
7export class Placeholder<T> {
8 #listeners: ((value: T) => void)[] = [];
9 setValue(value: T) {
10 for (const listener of this.#listeners) {
11 listener(value);
12 }
13 }
14
15 onValue(cb: (value: T) => void) {
16 this.#listeners.push(cb);
17 }
18}
19