-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move shortcuts to the bridge event api
Signed-off-by: Axel Boberg <[email protected]>
- Loading branch information
1 parent
66bb341
commit 3e37d7f
Showing
12 changed files
with
217 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-FileCopyrightText: 2024 Sveriges Television AB | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @class LazyValue | ||
* @description A wrapper around any value that can be awaited | ||
*/ | ||
class LazyValue { | ||
#value | ||
|
||
/** | ||
* @typedef {{ | ||
* resolve: () => {} | ||
* }} PromiseInit | ||
* | ||
* @type { PromiseInit[] } | ||
*/ | ||
#promises = [] | ||
|
||
/** | ||
* Set a new value, | ||
* will resolve any waiting promises | ||
* @param { any } value | ||
*/ | ||
set (value) { | ||
this.#value = value | ||
|
||
/* | ||
Resolve any waiting promises | ||
*/ | ||
for (const promise of this.#promises) { | ||
promise.resolve(value) | ||
} | ||
this.#promises = [] | ||
} | ||
|
||
/** | ||
* Get the current value | ||
* @returns { any } | ||
*/ | ||
get () { | ||
return this.#value | ||
} | ||
|
||
/** | ||
* Get the value lazily | ||
* through a promise, | ||
* | ||
* the promise will be resolved | ||
* as soon as a value is set | ||
* | ||
* @returns { Promise.<any> } | ||
*/ | ||
getLazy () { | ||
if (this.#value) { | ||
return this.#value | ||
} | ||
return new Promise(resolve => { | ||
this.#promises.push({ resolve }) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = LazyValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.