Skip to content
DataBatcher implementation in deno
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE improving example Apr 21, 2019
tsconfig.json initial implementation Apr 21, 2019


The ideas of DataLoader but applied to both loading and saving.

Example Usage

import { DataBatcher } from "./mod.ts";

const example = { 1: "one", 3: "three" };

async function loadBatch(ids: [number]) {
  // do some fancy work here to fetch all records with the given ids
  // if record is not found for a given id, then return null, or if an error occurs
  return => example[id] || null);

async function saveBatch(writes: [any,any][]) {
  // do something super fancy to perform the writes in batch
  // Returning an Error if something goes wrong
  return[key, value]) => {
    example[key] = value;

async function run() {
  const batcher = new DataBatcher(loadBatch, saveBatch);

  const loaded = await Promise.all([
    batcher.load(1), // one
    batcher.load(2), // null
    batcher.load(3) // three
  console.log(loaded); // [ "one", null, "three" ] 

  // Make change
  await, "TWO");

  // Load changed, note it is no longer null
  console.log(await batcher.load(2)); // TWO

You can’t perform that action at this time.