Welcome to the Linux Foundation Forum!

Chapter 9 - Typo in the last section example

jozef.radonak Posts: 1
edited March 2022 in LFW211 Class Forum

The last section of the Chapter 9 on **Promise-Based Single Use Listener and AbortController ** has small typo in the last example of canceling the timeout with the signal.
There is a missing parameter in setTimeout method call.

setTimeout(2000 * Math.random(), { signal }).then(() => { sometimesLaggy.emit('ping') })
is missing the second optional argument of value where options are used instead.
As per documentation timersPromises.setTimeout([delay[, value[, options]]])
This cause the timeout not to be canceled.

Correct would be e.g.
setTimeout(2000 * Math.random(), undefined, { signal }).then(() => { sometimesLaggy.emit('ping') })



Upcoming Training