Augusto Moura (2018-09-07T23:18:30.000Z)
augusto.borgesm at gmail.com (2018-09-07T23:32:04.531Z)
Why would you destroy a node and `.then()` pause it? It doesn't make sense even in plain English. If the contract of the method (expected behavior) is to destroy the internal node, using it after is a error. You can easily reimplement your use case reversing the logic: ```` js setTimeout(() => { demo.node.pause(); demo.destroy(); }, 3000); ```` Another solution is to implement a `beforeDestroy` event emitter and listen to it, this way is certain that the code will be executed always before the node is gone and after any async destroy logic: ```` js class Demo { constructor(el) { this.beforeDestroy = new EventEmitter(); // Using the @angular/core EventEmitter because is more "close to English" this.node = el; } destroy() { return new Promise(resolve => resolve()) .then(() => this.beforeDestroy.emit()) .finally(() => { this.node = null; }); } } const demo = new Demo(document.querySelector('video')); demo.beforeDestroy.subscribe(() => { demo.node.pause(); }); setTimeout(() => { demo.destroy(); }, 3000); ```` Anyway, the `then`, `catch` and `finally` methods mimic the serial try/catch/finally, simply doesn't make sense finally statements protecting code beyond it's try block definition, and chaining new `.then`s _are_ beyond the promise definition. Also, async functions already has finally blocks implementations in the same way as the current `.finally` method spec, implementing a different behaviour would be unnecessarily confusing.