minor sdk tweaks (#2828)

This commit is contained in:
Aiden McClelland
2025-02-12 15:08:13 -07:00
committed by GitHub
parent 6dc9a11a89
commit 890c31ba74
7 changed files with 214 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ export class GetSslCertificate {
) {}
/**
* Returns the system SMTP credentials. Restarts the service if the credentials change
* Returns the an SSL Certificate for the given hostnames if permitted. Restarts the service if it changes
*/
const() {
return this.effects.getSslCertificate({
@@ -19,7 +19,7 @@ export class GetSslCertificate {
})
}
/**
* Returns the system SMTP credentials. Does nothing if the credentials change
* Returns the an SSL Certificate for the given hostnames if permitted. Does nothing if it changes
*/
once() {
return this.effects.getSslCertificate({
@@ -27,8 +27,9 @@ export class GetSslCertificate {
algorithm: this.algorithm,
})
}
/**
* Watches the system SMTP credentials. Takes a custom callback function to run whenever the credentials change
* Watches the SSL Certificate for the given hostnames if permitted. Returns an async iterator that yields whenever the value changes
*/
async *watch() {
while (true) {
@@ -44,4 +45,34 @@ export class GetSslCertificate {
await waitForNext
}
}
/**
* Watches the SSL Certificate for the given hostnames if permitted. Takes a custom callback function to run whenever it changes
*/
onChange(
callback: (
value: [string, string, string] | null,
error?: Error,
) => void | Promise<void>,
) {
;(async () => {
for await (const value of this.watch()) {
try {
await callback(value)
} catch (e) {
console.error(
"callback function threw an error @ GetSslCertificate.onChange",
e,
)
}
}
})()
.catch((e) => callback(null, e))
.catch((e) =>
console.error(
"callback function threw an error @ GetSslCertificate.onChange",
e,
),
)
}
}