remijs / remi-runner

A remi extension that allows to register plugins that return promises or are syncronous
MIT License
0 stars 0 forks source link

Expected resolve() to pass result back #1

Open GarthDB opened 8 years ago

GarthDB commented 8 years ago

I prefer using promises, but I was expecting to be able to return some results back with the resolve method.

const remi = require('remi')
const remiRunner = require('remi-runner')

const app = {}
const registrator = remi(app)

registrator.hook(remiRunner())

registrator.register([cbPlugin, promisePlugin, syncPlugin]).then(function(results){
  console.log(results);
  // maybe returned as an object when registering an array of plugins:
  // { cbPlugin: '', promisePlugin: 'Here are the results', syncPlugin:'' }
  // or only include those plugins that actually have a parameter in the resolve method:
  // { promisePlugin: 'Here are the results' }
});

// a traditional plugin that uses an error-first-callback
// this will work w/o using the remi-runner
function cbPlugin(app, opts, next) {
  // ...
  next()
}

cbPlugin.attributes = { name: 'cbPlugin' }

// a plugin that returns a Promise. This type of plugin will be registered correctly
// only if remi is hooked with remi-runner
function promisePlugin(app, opts) {
  // ...
  return Promise.resolve('Here are the results')
}

cbPlugin.attributes = { name: 'promisePlugin' }

// a synchronous plugin. This type of plugin will be registered correctly
// only if remi is hooked with remi-runner
function syncPlugin(app, opts) {
  // ...
}

cbPlugin.attributes = { name: 'syncPlugin' }
zkochan commented 8 years ago

I see what you need. I can look into it tommorow. Maybe it can be added to the lib.

From the other side, have you considered using something like run-async + Promise.all?