mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.42k stars 1.14k forks source link

promises? #752

Open mark-hahn opened 4 years ago

mark-hahn commented 4 years ago

Is there any way to use a promise instead of a callback? I've gotten to where I hate callbacks.

kcrawfordus commented 4 years ago

this worked for me:

const papaPromise = (importFile) => new Promise((resolve, reject) => {
    const file = fs.createReadStream(importFile);
    Papa.parse(file, {
        header: true,
        complete: function(results) {
            resolve(results);
        },
        error: function(error) {
            reject(error);
        }
    });
})
const results = await papaPromise(importFile);
pokoli commented 4 years ago

@kcrawfordus thanks for your snipet. It will be great if you can provide a PR to include it as part of papaParse docs

custompro12 commented 4 years ago

Any plans to have the API itself support promises?

pokoli commented 4 years ago

@custompro12 not from my side but I will be happy to review a PR that ads support for it

robclancy commented 3 years ago

Was confusing seeing an undefined return type lol, almost had the callback pattern purged from my mind.

muezz commented 11 months ago

Any update on this?