Chatie / db

Database for Chatie
https://www.chatie.io
Apache License 2.0
0 stars 0 forks source link

Does not run the `finally {}` block after `try {}` and exit with code 0 #23

Open huan opened 6 years ago

huan commented 6 years ago

See: https://stackoverflow.com/questions/49728838/node-js-program-does-not-run-the-finally-block-after-try-and-exit-with

Code to Re-Produce

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()