Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ./test-lib.js
  2. 'use strict'
  3.  
  4. const Promise = require( 'bluebird' )
  5.  
  6. module.exports = ( str, cb ) => {
  7.     const endResult = ( txt ) => {
  8.         return new Promise( ( res, rej ) => {
  9.             res( 'You said ' + txt )
  10.         })
  11.     }
  12.     return endResult(str).asCallback(cb);
  13. }
  14.  
  15. // app.js
  16. 'use strict'
  17.  
  18. const Testlib = require('./test-lib')
  19.  
  20. Testlib('foo', ( err, data ) => {
  21.     if( err )
  22.         console.error('ERROR:',err)
  23.     else
  24.         console.log('DATA:',data)
  25. })
  26.  
  27. Testlib('bar')
  28.     .then( data => {
  29.         console.log('DATA:',data)
  30.     })
  31.     .catch( err => {
  32.         console.error('ERROR:',err)
  33.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement