DsPdfJS API - v9.1.0
    Preparing search index...

    Function withObjectManager

    • Decorator function that automatically manages resources for class methods and functions. Creates an ObjectManager that is automatically disposed when the function completes. Supports both synchronous and asynchronous functions while preserving return values.

      Parameters

      • target: any

        The class prototype, constructor, or function to be decorated

      • OptionalpropertyKey: string

        The name of the method being decorated (for class methods)

      • Optionaldescriptor: PropertyDescriptor

        The property descriptor for the method (for class methods)

      Returns any

      The modified property descriptor or wrapped function

      This decorator provides automatic resource management for functions and class methods. It handles both synchronous and asynchronous operations, ensuring proper cleanup even when exceptions occur or promises are rejected.

      Usage as a method decorator:

      class PdfService {
      @withObjectManager
      createPdf() {
      const doc = new PdfDocument(); // Automatically registered with ObjectManager
      const brush = new Brush(); // Automatically registered with ObjectManager
      ...

      @withObjectManager
      async createPdfAsync() {
      const doc = new PdfDocument();
      await someAsyncOperation();
      ...

      Usage as a function wrapper:

      const createPdf = withObjectManager(() => {
      const doc = new PdfDocument();
      ...
      });

      const createPdfAsync = withObjectManager(async () => {
      const doc = new PdfDocument();
      await someAsyncOperation();
      ...
      });

      Usage with new-style decorators (TypeScript 5.0+):

      class Service {
      @withObjectManager
      method() {
      // Automatic resource management
      }
      }

      When resource cleanup fails. Errors are logged but not rethrown to preserve original error flow.