Skip to content

pambda/pambda-async-init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pambda-async-init

Installation

npm i pambda-async-init

Usage

const { compose, createLambda } = require('pambda');
const { asyncInit } = require('pambda-async-init');

exports.handler = createLambda(
  compose(
    asyncInit({
      config: callback => readJson('config.json', callback),
    }, (err, result) => {
      if (err) {
        return next => (event, context, callback) => callback(err);
      }

      if (!result.config) {
        return;
      }

      return next => (event, context, callback) => {
        context.config = result.config;

        next(event, context, callback);
      };
    }),

    next => (event, context, callback) => {
      // context.config can be used.
    },
  )
);

asyncInit(tasks, callback)

  • tasks
  • callback(err, result)
    • A function that is called when the tasks is completed or an error occurs.
    • This function must return either a pambda function that uses the result, or a falsy value that means delegating to a subsequent pambda without doing anything.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published