Skip to content

Promise support as well as other useful stuff for Seneca.js

License

Notifications You must be signed in to change notification settings

wyvernzora/seneca-as-promised

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seneca

Promise support for Seneca.js microservices

seneca-as-promised

npm version Build Status

This plugin adds support for promises to Seneca, courtesy of Bluebird.

Install

To install, use npm

npm install seneca-as-promised

Add in your code

require('seneca')()
  .use('seneca-as-promised');

API

addAsync()

Behaves exactly like seneca.add(), but supports promise-returning functions.

seneca.addAsync('role:hex,color:red', async function(msg) {
  await someAsyncStuff();
  return { color: '#FF0000' };
});

Actions added via addAsync() have an additional priorAsync method in the this context, which is a promisified version of this.prior().

actAsync()

Behaves exactly like seneca.act(), but returns a promise. Also supports callbacks.

const color = await seneca.actAsync('role:hex,color:red');

wrapAsync()

Behaves exactly like seneca.wrap(), but supports promise-returning functions.

seneca.wrapAsync('role:hex', async function(msg) {
  const color = await this.priorAsync(msg);
  color.format = 'css';

  return color;
});

Wrappers added via wrapAsync() have an additional priorAsync method in the this context, which is a promisified version of this.prior().

License

Copyright (C) 2015-16, Denis Luchkin-Zhou. Licensed under MIT

About

Promise support as well as other useful stuff for Seneca.js

Resources

License

Stars