Skip to content

Integrating with existing promise based APIs

Kory Nunn edited this page Sep 2, 2019 · 1 revision

Using a mix of promises and callbacks

function combineFileAndTweets(file, tweetsResponse, callback){
    callback(null, file + tweetsResponse.body)
}

function myTask(callback){

    var someFileRighto = righto(fs.readFile, './filePath', 'utf8'); // A righto
    var tweetsPromise = got('https://api.twitter.com/1.1/search/tweets.json'); // A Promise
    var combinedRighto = righto(combineFileAndTweets, someFileRighto, tweetsPromise);  // righto handles both

    combinedRighto(callback)
}
Clone this wiki locally