CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tmp-promise

The tmp package with promises support and disposers.

93

1.78x
Overview
Eval results
Files

task.mdevals/scenario-7/

Temporary Workspace Processor

Build a function that processes data items in an isolated temporary workspace with automatic cleanup.

Requirements

Implement a function processDataInWorkspace that:

  1. Creates a temporary workspace directory
  2. Within that workspace, creates a temporary processing file
  3. Writes each data item to the file (one per line, prefixed with "PROCESSED: ")
  4. Reads back all processed data from the file
  5. Returns the workspace path and the processed data
  6. Automatically cleans up all temporary resources even if errors occur

The function accepts an array of data items (strings) and returns a promise that resolves to:

{
  workspacePath: string,    // Path of the temporary workspace used
  processedData: string[]   // Array of processed items
}

Implementation Details

  • Use automatic cleanup patterns for both directory and file
  • Create the temporary file inside the temporary directory
  • Ensure cleanup happens even when errors occur

Test Cases

  • It processes an array of data items and returns processed results @test
  • It creates temporary file inside temporary directory @test
  • It cleans up both file and directory after processing @test
  • It cleans up resources even when processing throws an error @test

Implementation

@generates

API

/**
 * Processes data items in a temporary workspace with automatic cleanup
 * @param {string[]} dataItems - Array of data items to process
 * @returns {Promise<{workspacePath: string, processedData: string[]}>}
 */
async function processDataInWorkspace(dataItems) {
  // Implementation here
}

module.exports = { processDataInWorkspace };

Dependencies { .dependencies }

tmp-promise { .dependency }

Provides temporary file and directory management with automatic cleanup support.

Install with Tessl CLI

npx tessl i tessl/npm-tmp-promise

tile.json