Skip to content

Commit

Permalink
add current status and idle cb
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 authored Apr 21, 2022
1 parent 1c0dad6 commit fdde22c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ export class SmtpClient {
await this.#conn.close();
}

get isSending() {
return this.#currentlySending
}

#idleCB = new Set<()=>void>()

get waitIdle() {
if(!this.isSending) return Promise.resolve()

return new Promise<void>((res) => {this.#idleCB.add(res)})
}

#currentlySending = false;
#sending: (() => void)[] = [];

Expand All @@ -90,6 +102,7 @@ export class SmtpClient {
#queNextSending() {
if (this.#sending.length === 0) {
this.#currentlySending = false;
this.#idleCB.forEach(cb => cb())
return;
}

Expand Down

0 comments on commit fdde22c

Please sign in to comment.