GETTING STARTED

MAIN CONCEPTS

API

createPromise(function)

Tuft is a promise-based framework and thus does not support callback-based functions. createPromise() is exported as a convenience for dynamically converting a callback-based function to one that returns a promise.

It accepts a function that receives an error-first callback as its first and only argument. If the callback is then invoked with an error as its first argument, the promise will reject with that error. Otherwise, the promise will be resolved with any remaining arguments being returned as an array.

const { createPromise } = require('tuft')
const { stat } = require('fs')

async function callStat() {
  try {
    const [stats] = await createPromise(done => {
      stat('.', done)
    })

    console.log(`This directory is owned by ${stats.uid}`)
  }

  catch (err) {
    console.error(err)
  }
}

If possible, using Node's built-in promisify function to convert a callback-based function to a promise-based function is preferred. createPromise() is intended solely as a convenience for situations where a method or function cannot be converted by promisify().