-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(yagna): added behaviour subjects for events in yagna-api to supp…
…ort basic event-bus cases * refactor: switched the existing codebase to the subjects * refactor: added graceful shutdown behaviour for yagna.disconnect * chore: applied remark from CR
- Loading branch information
Showing
12 changed files
with
319 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import sleep from "./sleep"; | ||
|
||
export { sleep }; | ||
export * as runtimeContextChecker from "./runtimeContextChecker"; | ||
export { Logger } from "./logger/logger"; | ||
export { nullLogger } from "./logger/nullLogger"; | ||
export { defaultLogger } from "./logger/defaultLogger"; | ||
export * as EnvUtils from "./env"; | ||
export { YagnaApi, YagnaOptions } from "./yagna/yagnaApi"; | ||
export { YagnaEventSubscription } from "./yagna/yagnaApi"; | ||
export { YagnaApi, YagnaOptions, YagnaEventSubscription } from "./yagna/yagnaApi"; |
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,40 @@ | ||
import { clearInterval } from "node:timers"; | ||
import { GolemTimeoutError } from "../error/golem-error"; | ||
|
||
/** | ||
* Utility function that helps to block the execution until a condition is met (check returns true) or the timeout happens. | ||
* | ||
* @param {function} check - The function checking if the condition is met. | ||
* @param {Object} [opts] - Options controlling the timeout and check interval in seconds. | ||
* @param {number} [opts.timeoutSeconds=15] - The timeout value in seconds. Default is 15 seconds. | ||
* @param {number} [opts.intervalSeconds=1] - The interval between condition checks in seconds. Default is 1 second. | ||
* | ||
* @return {Promise<void>} - Resolves when the condition is met or rejects with a timeout error if it wasn't met on time. | ||
*/ | ||
export function waitForCondition( | ||
check: () => boolean, | ||
opts = { timeoutSeconds: 15, intervalSeconds: 1 }, | ||
): Promise<void> { | ||
let verifyInterval: NodeJS.Timeout | undefined; | ||
let waitTimeout: NodeJS.Timeout | undefined; | ||
|
||
const verify = new Promise<void>((resolve) => { | ||
verifyInterval = setInterval(() => { | ||
if (check()) { | ||
clearInterval(verifyInterval); | ||
resolve(); | ||
} | ||
}, opts.intervalSeconds * 1000); | ||
}); | ||
|
||
const wait = new Promise<void>((_, reject) => { | ||
waitTimeout = setTimeout(() => { | ||
reject(new GolemTimeoutError(`Condition was not met within ${opts.timeoutSeconds}s`)); | ||
}, opts.timeoutSeconds * 1000); | ||
}); | ||
|
||
return Promise.race([verify, wait]).finally(() => { | ||
clearInterval(verifyInterval); | ||
clearTimeout(waitTimeout); | ||
}); | ||
} |
Oops, something went wrong.