Concepts
Publication snapshot
Snapshot selection gives a defined behavior if a callback removes another callback during a notification.
Formal Syntax & Structure
javascript syntaxjavascript
for (const listener of [...listeners]) listener(value)Working Example
Example Snippetjavascript
(async () => {const seen=[],listeners=new Set();const second=()=>seen.push("B");listeners.add(()=>{seen.push("A");listeners.delete(second);});listeners.add(second);for(const f of [...listeners])f();for(const f of [...listeners])f();console.log(seen.join(","));})()