Options
All
  • Public
  • Public/Protected
  • All
Menu

Module promise/fromCallback

Index

References

Interfaces

Functions

References

Renames and re-exports fromCallback

Functions

  • fromCallback(fn: (callback: (err?: any, ...args: any[]) => any) => any, thisArg?: any): Promise<any>
  • Returns a promise that is resolved by a node style callback function. This is the most fitting way to do on the fly promisification when libraries don't expose classes for automatic promisification by undefined.

    The resolver function is passed a callback that expects to be called back according to error-first node conventions.

    Setting multiArgs to true means the resulting promise will always fulfill with an array of the callback's success value(s). This is needed because promises only support a single success value while some callback API's have multiple success value. The default is to ignore all but the first success value of a callback function.

    example

    const fs = require('fs');

    fromCallback(callback => fs.readFile('filename.txt', callback)) .then(buffer => buffer.toString().trim()); // ...

    Parameters

    • fn: (callback: (err?: any, ...args: any[]) => any) => any
        • (callback: (err?: any, ...args: any[]) => any): any
        • Parameters

          • callback: (err?: any, ...args: any[]) => any
              • (err?: any, ...args: any[]): any
              • Parameters

                • Optional err: any
                • Rest ...args: any[]

                Returns any

          Returns any

    • Optional thisArg: any

    Returns Promise<any>

Generated using TypeDoc