DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on

util.promisify in Roo-Code codebase.

In this article, we review promisify method. You will learn:

  1. What is util.promisify?

  2. What is Roo-Code?

  3. Usage example.

What is util.promisify?

Util is a NodeJS API. It has a lot of method defined. Check the util page. We are interested in promisify.

Promisify

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.
});
Enter fullscreen mode Exit fullscreen mode

Learn more about promisify.

What is Roo-Code?

Roo Code gives you a whole dev team of AI agents in your code editor.

What Can Roo Code Do For YOU?

  • Generate Code from natural language descriptions and specs

  • Adapt with Modes: Code, Architect, Ask, Debug, and Custom Modes

  • Refactor & Debug existing code

  • Write & Update documentation

  • Answer Questions about your codebase

  • Automate repetitive tasks

  • Utilize MCP Servers

Modes

Roo Code adapts to how you work:

  • Code Mode: everyday coding, edits, and file ops

  • Architect Mode: plan systems, specs, and migrations

  • Ask Mode: fast answers, explanations, and docs

  • Debug Mode: trace issues, add logs, isolate root causes

  • Custom Modes: build specialized modes for your team or workflow

Learn more about Roo-Code.

Usage example

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"
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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
  }
 }
...
Enter fullscreen mode Exit fullscreen mode

About me:

Hey, my name is ramunarasinga. Email: ramunarasinga@gmail.com

Tired of AI slop?

I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built

References:

  1. Roo-Code/packages/…/worktree/worktree-service.ts#L10.

  2. nodejs.org/api/util.html#utilpromisifyoriginal.

Top comments (0)