Domain.prototype.bind - Node documentation
method Domain.prototype.bind

Usage in Deno

import { Domain } from "node:domain";
Domain.prototype.bind<T extends Function>(callback: T): T

The returned function will be a wrapper around the supplied callback function. When the returned function is called, any errors that are thrown will be routed to the domain's 'error' event.

const d = domain.create();

function readSomeFile(filename, cb) {
  fs.readFile(filename, 'utf8', d.bind((er, data) => {
    // If this throws, it will also be passed to the domain.
    return cb(er, data ? JSON.parse(data) : null);
  }));
}

d.on('error', (er) => {
  // An error occurred somewhere. If we throw it now, it will crash the program
  // with the normal line number and stack message.
});

Type Parameters

T extends Function

Parameters

callback: T

The callback function

Return Type

T

The bound function