🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

async-task-reconciler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-task-reconciler

[![coverage](https://img.shields.io/codecov/c/github/LPegasus/async-task-reconciler.svg?style=flat-square)](https://codecov.io/gh/LPegasus/async-task-reconciler)[![npm version](https://badge.fury.io/js/async-task-reconciler.svg)](https://www.npmjs.com/pac

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
150%
Maintainers
1
Weekly downloads
 
Created
Source

async-task-reconciler

coveragenpm version

Use to combine async task, cache tasks' results.

Sample

import { AsyncTaskReconciler } from 'async-task-reconciler';

const reconciler = new AsyncTaskReconciler();
// defaultOptions use no cache.
// But if a task with key at pending status,
// before the task resolved, some other tasks
// with the same key come, reconciler won't execute
// these tasks. When the first task fulfilled, all
// the others with the same key will be resolved.

// imagine provide an api which is a query search,
// and request to DB or other backend costs a while.
router.get('/detail/:id', async (req, res) => {
  const key = req.params.id;

  try {
    const queryResult = await reconciler.addTask(() => {
      return service.queryDetail({ id: key });
    }, key);
    res.json(queryResult);
  } catch(e) {
    // Handle error
  }
});

API

ctorOptions

export interface AsyncTaskReconcilerOptions {
  cache?:
    | boolean
    | {
        strategy: 'FIFO' | 'LRU';	// clear cache strategy
        size: number;							// cache size
      };
  concurrent?: number;						// parallel count
}

.addTask

<T>(task: () => Promise<T>, key?: string) => Promise<T>

  • fn

    async task to execute

  • key

    task identifier

.clearCache

() => void

delete caches

FAQs

Package last updated on 12 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts