Make the speaker retain its last spoken message

This commit is contained in:
Talia 2021-11-25 10:04:27 +01:00
parent 5036259d75
commit 8161b80081
1 changed files with 5 additions and 1 deletions

View File

@ -2,16 +2,20 @@ class Speaker {
#callbacks = new Set() #callbacks = new Set()
#immediate #immediate
#scheduled = [] #scheduled = []
#current
constructor(immediate) { constructor(immediate, current=[]) {
this.#immediate = immediate this.#immediate = immediate
this.#current = current
} }
listen(callback) { listen(callback) {
this.#callbacks.add(callback) this.#callbacks.add(callback)
return this.#current
} }
speak(...args) { speak(...args) {
this.#current = args
if (this.#immediate) { if (this.#immediate) {
for (let callback of this.#callbacks) { for (let callback of this.#callbacks) {
callback(...args) callback(...args)