import {
BehaviorSubject,
} from 'rxjs/Rx'
async function main() {
const subject = new BehaviorSubject<number>(-1)
const obs = subject.asObservable().share()
/**
* if comment the following line, this program will output right as the following three lines:
*
* 1. BEFORE TRY
* 2. AFTER TRY
* 3. FINALLY
*
* otherwise, the output will only be:
*
* 1. BEFORE TRY
*
* very wired!
*
*/
obs.subscribe()
try {
console.log('1. BEFORE TRY')
await obs.first().toPromise()
console.log('2. AFTER TRY')
} finally {
console.log('3. FINALLY')
}
}
main()
See: https://stackoverflow.com/questions/49728838/node-js-program-does-not-run-the-finally-block-after-try-and-exit-with
Code to Re-Produce