Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-decorators

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-decorators

async-await and 'promise methods' decorators

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

There are some helpfull decorators in this project for async class methods and functions.

#Install

npm install --save async-decorators

#Import

import {memoize, serialize, isSkipError} from 'async-decorators';

#Memoize decorator
has parameters expireMs and cacheSize
usage:

class Action {
  @memoize({expireMs: K_EXPIRE_MS, cacheSize: 256})
  async query(p1, p2) {
    return await getDataAsync({p1, p2});
  }
}

or just

const asyncFn = memoize(async (x) => {
  return await ....
});

See example source

npm run example_memoize

and test source

npm run test_memoize

#Serialize decorator Serializes async method calls. (Make a new async call only if previous is completed) If there are more than one pending async calls, skip all but the last.

usage:

class Action {
  @serialize()
  async query(p1, p2) {
    return await getDataAsync({p1, p2});
  }
}

or just

const sfn = serialize(async (x) => {
  return await ....
})

See example source

npm run example_serialize

#Both decorator usage

class Action {
  @serialize()
  @memoize({expireMs: K_EXPIRE_MS})
  async query(p1, p2) {
    return await getDataAsync({p1, p2});
  }
}

See example source

npm run example_ser_memoize

Keywords

FAQs

Package last updated on 30 Oct 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc