sindresorhus / tempy

Get a random temporary file or directory path
MIT License
423 stars 26 forks source link

Returning values from `.task` functions #28

Closed Richienb closed 4 years ago

Richienb commented 4 years ago

If a function that is supposed to return data, uses a .task function, the only way to pass data back out of the scope is like this:

const tempy = require('tempy');

module.exports = async () => {
    let result
    await tempy.file.task(tempFile => {
        // Use tempFile
        result = ...
    })
    return result
}

Since .task functions don't already return something, they could simply reflect the returned values:

const tempy = require('tempy');

module.exports = async () => {
    return await tempy.file.task(tempFile => {
        // Use tempFile
        return ...
    })
}
sindresorhus commented 4 years ago

Good idea 👍🏻