For async producers a clean-up mechanism is needed in order to free up memory or ensure that certain effects to not occur as the initiator does no longer exist.
The simplest way to implement this is using a return statement with a function that will be called by the engine when the producer will be unmounted:
const producer: Producer = ({ stream = streamAPI, value = Update.value }) => {
const instance = stream.create({ }).on(x => {
value.set(x)
})
return () => instance.end()
}
For async producers a clean-up mechanism is needed in order to free up memory or ensure that certain effects to not occur as the initiator does no longer exist.
The simplest way to implement this is using a return statement with a function that will be called by the engine when the producer will be unmounted: