Socket
Book a DemoInstallSign in
Socket

combine-result

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

combine-result

Combine result

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

node-combine-result

Usage

Combine a few call to a single result which it's returned by first call.

Consider you have a few requests to reads a same file that is very huge let's say it about 1GB and assume it's a fixed file; in that case, u don't want to read the file in each request, so let's combine those requests to read the file just once.

const readFile = path => {
  return new Promise(resolve => {
    setTimeout(() => resolve('huge content'), 1000); // 1Gb file, read it cost 1000ms
  });
};

const combine = requrie('combine-result')();
const readFileCombined = path => {
  return combine(path, () => readFile(path));
}

// The following three will combine, read 'a.txt' and return it three times
readFileCombined('a.txt').then(val => console.log(val), err => console.log(err));
readFileCombined('a.txt').then(val => console.log(val), err => console.log(err));
readFileCombined('a.txt').then(val => console.log(val), err => console.log(err));

// The following two are combined
readFileCombined('b.txt').then(val => console.log(val), err => console.log(err));
readFileCombined('b.txt').then(val => console.log(val), err => console.log(err));

setTimeout(() => {
  // Reread 'a.txt' since lastest read 'a.txt' calls has returned.
  readFileCombined('a.txt').then(val => console.log(val), err => console.log(err));

  // The following three are combined
  readFileCombined('c.txt').then(val => console.log(val), err => console.log(err));
  readFileCombined('c.txt').then(val => console.log(val), err => console.log(err));
  readFileCombined('c.txt').then(val => console.log(val), err => console.log(err));
}, 1500);

Keywords

combine

FAQs

Package last updated on 26 Nov 2018

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.