0.1.5 • Published 9 years ago

async-decorators v0.1.5

Weekly downloads
10
License
MIT
Repository
github
Last release
9 years ago

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
0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.0.1

9 years ago