index.js 375 B

123456789101112131415161718192021
  1. 'use strict';
  2. var asyncDone = require('async-done');
  3. function settle(fn, done) {
  4. asyncDone(fn, function(error, result) {
  5. var settled = {};
  6. if (error != null) {
  7. settled.state = 'error';
  8. settled.value = error;
  9. } else {
  10. settled.state = 'success';
  11. settled.value = result;
  12. }
  13. done(null, settled);
  14. });
  15. }
  16. module.exports = settle;