Promisify takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.
Below is an example picked from the docs:
import { promisify } from 'node:util';import { stat } from 'node:fs';const promisifiedStat = promisify(stat);promisifiedStat('.').then((stats) => { // Do something with `stats`}).catch((error) => { // Handle the error.});
In the Roo-Code codebase, there is a file, worktree-service.ts. It has promisify imported as shown below, at the top of the file:
import { promisify } from "util"
How is this used? Roo-Code is making two methods return as a promise as shown below:
import { exec, execFile } from "child_process"import { promisify } from "util"...const execAsync = promisify(exec)const execFileAsync = promisify(execFile)
and then this promisified functions are used in the WorktreeService class as shown below:
/** * Service for managing git worktrees. * All methods are platform-agnostic and don't depend on VSCode APIs. */export class WorktreeService { /** * Check if git is installed on the system */ async checkGitInstalled(): Promise<boolean> { try { await execAsync("git --version") return true } catch { return false } }...