Skip to content

Commit caf0cc1

Browse files
authored
change idle promise implementation
1 parent fdde22c commit caf0cc1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

smtp.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,21 @@ export class SmtpClient {
7474
return this.#currentlySending
7575
}
7676

77-
#idleCB = new Set<()=>void>()
78-
79-
get waitIdle() {
80-
if(!this.isSending) return Promise.resolve()
81-
82-
return new Promise<void>((res) => {this.#idleCB.add(res)})
77+
get idle() {
78+
return this.#idlePromise
8379
}
8480

81+
#idlePromise = Promise.resolve()
82+
#idleCB = () => {}
83+
8584
#currentlySending = false;
8685
#sending: (() => void)[] = [];
8786

8887
#cueSending() {
8988
if (!this.#currentlySending) {
89+
this.#idlePromise = new Promise((res) => {
90+
this.#idleCB = res
91+
})
9092
this.#currentlySending = true;
9193
return;
9294
}
@@ -102,7 +104,7 @@ export class SmtpClient {
102104
#queNextSending() {
103105
if (this.#sending.length === 0) {
104106
this.#currentlySending = false;
105-
this.#idleCB.forEach(cb => cb())
107+
this.#idleCB()
106108
return;
107109
}
108110

0 commit comments

Comments
 (0)