Implement promisify()

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement promisify()

Approach

Return a new function that wraps the original callback-based function in a Promise. Pass all user arguments plus a final callback to the original function. In the callback, reject on error or resolve with the result, following the Node.js (err, result) convention.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Promisify Pattern

Why It Works

The adapter appends an error-first callback that bridges the callback world to the Promise world, enabling async/await usage with legacy Node.js-style APIs.

Updated Feb 2026