npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dadajam4/async-combiner

v0.2.1

Published

Service that combines multiple asynchronous requests into one

Downloads

5

Readme

async-combiner

Service that combines multiple asynchronous requests into one

Docs

Motivation

It was troublesome to implement each project individually to solve the following problems when creating the front-end screen, so I wanted to solve it (I want to make a method that can be used in common).

  • I have continuous requests for asynchronous processes that require the same result, and I want to solve those requests in one execution
  • For a heavy load asynchronous process, when the user's change request is continuously received, I want to delay the execution until the user's change request is not performed.
  • I want to reuse these mechanisms universally in NodeJS & browser
  • I want to use both TypeScript and non-raw JavaScript
  • I want to use a decorator to do simple coding in a syntax environment that supports decorators

Usage

Install package

npm install @dadajam4/async-combiner --save

In your code

Pure JavaScript

//
// Class base syntax
//
import { AsyncCombiner } from '@dadajam4/async-combiner';

class SomeClass extends AsyncCombiner {
  constructor(someValue1, someValue2) {
    super();
    this.someValue1 = someValue1;
    this.someValue2 = someValue2;
  }

  someHeavyAsyncFunc(url, query) {
    const condition = [url, query];
    return this.$asyncCombine(condition, () => this._func(url, query));
  }
  
  _someHeavyAsyncFuncExecutor(url, query) {

    /**
     * @see: https://github.com/axios/axios
     */
    return axios.get(url, { params: query });
  }
}

TypeScript

import { Combine } from '@dadajam4/async-combiner';

class SomeClass {
  
  // Of course you can also use `class extends`
  @Combine()
  someHeavyAsyncFunc(url, query) {
    /**
     * @see: https://github.com/axios/axios
     */
    return axios.get(url, { params: query });
  }
}

Mechanism and restrictions

Logic that uses the mechanism of this library should always match the response to the input parameters.
Do not use it for things like get requests that change frequently over time.
Inside the library, the parameters passed to the method are stored as a "condition object", and all requests of the same condition that are triggered before the processing is completed are combined into one execution.
When using the decorator, the parameters passed to the method are automatically converted into a condition object for convenience, but you may want to customize this depending on the condition of the parameter.
You can delay the execution of asynchronous processing if necessary. This feature can significantly reduce the backend service load, depending on the system load.
See the documentation for individual parameter settings.

Issues

  • I think there are scenes where I want the cancel function, but I have not implemented it yet. I also considered the approach using AbortController, but I think it is important that it can work with NodeJS as it is, so I would like to think of a way to solve this well.