Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ./test-lib.js
- 'use strict'
- const Promise = require( 'bluebird' )
- module.exports = ( str, cb ) => {
- const endResult = ( txt ) => {
- return new Promise( ( res, rej ) => {
- res( 'You said ' + txt )
- })
- }
- return endResult(str).asCallback(cb);
- }
- // app.js
- 'use strict'
- const Testlib = require('./test-lib')
- Testlib('foo', ( err, data ) => {
- if( err )
- console.error('ERROR:',err)
- else
- console.log('DATA:',data)
- })
- Testlib('bar')
- .then( data => {
- console.log('DATA:',data)
- })
- .catch( err => {
- console.error('ERROR:',err)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement