Surprised by Re-entrant Code

Some of the trickiest bugs I’ve seen happened because a function unexpectedly occurred multiple times on the call stack. Re-entrant ListenersTo illustrate, consider a TextField widget that implements the listener pattern: class TextField { var listeners = mutableListOf<Listener>() var value: String = "" set(value) { val previous = field if (value

Public Object
@jessewilson In the last sample code, you'd also need to iterate on a copy of the listeners' list to avoid the problem with unsubscribing from within a listener.
Either that or prevent mutating the listeners' list from within a listener.
@tbroyer good eye. I was wondering if anyone would catch that!
@jessewilson That's what teachers say when a student points at their mistake 🤣