Use a pattern along these lines:
function getValue(file) {
return lookupValue(file);
}
getValue('myFile.txt').then(function(res) {
// do whatever with res here
});
(although this is a bit redundant, I’m sure your actual code is more complicated)
More Related Contents:
- Issue in returning data retrieved from DB queries called in the loop
- Why is ‘this’ undefined inside class method when using promises? [duplicate]
- Are there still reasons to use promise libraries like Q or BlueBird now that we have ES6 promises? [closed]
- Proper way to skip a then function in Q Promises
- What happens if i reject / resolve multiple times in Kriskowal’s q?
- javascript promise not passing all arguments (using Q)
- How do I convert an existing callback API to promises?
- When is .then(success, fail) considered an antipattern for promises?
- Is it bad practice to have a constructor function return a Promise?
- Resolve promises one after another (i.e. in sequence)?
- Correct way to write a non-blocking function in Node.js
- Correct way to write loops for promise.
- Asynchronous exception handling with bluebird promises
- Promise Retry Design Patterns
- How to sequentially run promises with Q in Javascript?
- Handling multiple catches in promise chain
- How do I tell if an object is a Promise?
- Why do I need to await an async function when it is not supposedly returning a Promise?
- Catching Errors in JavaScript Promises with a First Level try … catch
- using async await and .then together
- Why cant I inline call to res.json?
- Promises: Repeat operation until it succeeds?
- Why is my function returning Promise { } [duplicate]
- Difference of using async / await vs promises?
- Javascript Asynchronous Exception Handling with node.js
- Produce a promise which depends on recursive promises
- Promise.all().then() resolve?
- Properly batch nested promises in Node
- How to Promisify this function – nodejs [duplicate]
- Promise.resolve().then vs setImmediate vs nextTick