TypeScript – Waitable Promise Utility

Home   »   TypeScript – Waitable Promise Utility

/**
 * @file Implementation - wait
 * @see https://github.com/TypeStrong/ts-node/issues/245#issuecomment-406608252
 */

/**
 * Creates a waitable promise.
 *
 * References:
 *
 * - https://github.com/TypeStrong/ts-node/issues/245#issuecomment-406608252
 *
 * @template T - Resolved value
 *
 * @param {Promise} promise - Promise to wait for
 * @return {T} - Value from promise
 */
function wait(promise: Promise): T {
  /* eslint-disable-next-line @typescript-eslint/no-var-requires */
  return require('deasync2').await(promise)
}

export default wait

Leave a Reply

Your email address will not be published.