Skip to content

Commit

Permalink
change idle promise implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 authored Apr 21, 2022
1 parent fdde22c commit caf0cc1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ export class SmtpClient {
return this.#currentlySending
}

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

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

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

#idlePromise = Promise.resolve()
#idleCB = () => {}

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

#cueSending() {
if (!this.#currentlySending) {
this.#idlePromise = new Promise((res) => {
this.#idleCB = res
})
this.#currentlySending = true;
return;
}
Expand All @@ -102,7 +104,7 @@ export class SmtpClient {
#queNextSending() {
if (this.#sending.length === 0) {
this.#currentlySending = false;
this.#idleCB.forEach(cb => cb())
this.#idleCB()
return;
}

Expand Down

0 comments on commit caf0cc1

Please sign in to comment.