doc/Closures.md
Some considerations:
xxxxx.yyyyyClosed() method is equivalent to the corresponding C++ ~Xxxxx() destructor. They both silently destroy things without generating any internal notifications/events.
xxxxx.yyyyyClosed() produces public JS event xxxxx.on('yyyyyclose'), but that's not internal stuff.router.workerClosed().worker.on('died').router.workerClosed().delete router.router.on('workerclose').WORKER_CLOSE_ROUTER:
delete router.transport.routerClosed().router.on('@close') (so the JS Worker cleans its map).delete transport.producer.transportClosed().consumer.transportClosed().transport.on('routerclose').ROUTER_CLOSE_TRANSPORT.
transport->Close() (so the C++ Transport will notify the C++ Router about closed Producers and Consumers in that Transport).delete transport.producer.transportClosed().transport.on('@producerclose') (so the JS Router cleans its maps).consumer.transportClosed().transport.on('@close') (so the JS Router cleans its map).delete producer.delete consumer.listener->OnTransportProducerClosed(this, producer) (so the C++ Router cleans its maps and calls consumer->ProducerClosed() on its associated Consumers).delete producer.listener->OnTransportConsumerClosed(this, consumer) (so the C++ Router cleans its maps).delete consumer.NOTE: If a Transport holds a Producer and a Consumer associated to that Producer, ugly things may happen when calling Transport::Close():
Consumer::ProducerClosed()).
Transport::mapConsumers everything would be ok when later iterating the map of Consumers.consumer.on('producerclose') is not called since consumer.on('transportclose') is supposed to happen before.
Consumer has removed its channel notifications within its transportClosed() method.mapProducerConsumers. For each Consumer:
consumer->ProducerClosed().mapProducerConsumers with key producer.mapProducers with key producer->id.mapConsumerProducer.mapProducerConsumers entry for the given Producer.mapConsumerProducer with key consumer.producer.on('transportclose').TRANSPORT_CLOSE_PRODUCER.
listener->OnTransportProducerClosed(this, producer) (so the C++ Router cleans its maps and calls consumer->ProducerClose() on its associated Consumers).delete producer.producer.on('@close') (so the JS Transport cleans its map and will also emit private JS transport.on('@producerclose') so the JS Router cleans its map).consumer.on('transportclose').TRANSPORT_CLOSE_CONSUMER.
listener->OnTransportConsumerClosed(this, consumer) (so the C++ Router cleans its maps).delete consumer.consumer.on('@close') (so the JS Transport cleans its map).Router::OnTransportProducerClosed() listener.producerclose to the JS Consumer.
consumer.on('@produceclose') (so the JS Transport cleans its map).consumer.on('produceclose').listener->onConsumerProducerClosed() which:
listener->OnTransportConsumerClosed()), and