PapaParse icon indicating copy to clipboard operation
PapaParse copied to clipboard

promises?

Open mark-hahn opened this issue 5 years ago • 6 comments

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

mark-hahn avatar Dec 13 '19 06:12 mark-hahn

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);

kcrawfordus avatar Dec 19 '19 01:12 kcrawfordus

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

pokoli avatar Dec 19 '19 10:12 pokoli

Any plans to have the API itself support promises?

custompro12 avatar Feb 12 '20 17:02 custompro12

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

pokoli avatar Feb 12 '20 18:02 pokoli

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

robclancy avatar Mar 16 '21 08:03 robclancy

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

Cool. I will add a pull request on the weekend 👍

code4break avatar Jun 30 '23 09:06 code4break

Any update on this?

muezz avatar Oct 17 '23 22:10 muezz