Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accumulate doesn't work correctly if debounced function returns nothing (undefined) #25

Open
PieterScheffers opened this issue Feb 11, 2020 · 1 comment

Comments

@PieterScheffers
Copy link

PieterScheffers commented Feb 11, 2020

The error It get is this:

(node:18886) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
    at /c/repositories/proforto/Profortool/grand-bazaar/packages/tricorp-materializer/node_modules/debounce-promise/dist/index.js:43:23
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Promise.all (index 0)

Example code:

const debounce = require('debounce-promise')

async function doIt(name) {
    console.log('name', name) // [ [ 'first' ], [ 'second' ], [ 'third' ] ]
    // return name // When returning a value, no error is thrown
}

const doItPlus = debounce(doIt, 100, { accumulate: true })

async function main() {
    const promises = [
        doItPlus('first'),
        doItPlus('second'),
        doItPlus('third'),
    ]

    await Promise.all(promises)
}

main()

Node version: v13.3.0

@PieterScheffers
Copy link
Author

PieterScheffers commented Feb 11, 2020

Catching errors of promises seperately.

const debounce = require('debounce-promise')

async function doIt(name) {
    console.log('name', name) // [ [ 'first' ], [ 'second' ], [ 'third' ] ]
    // return name // When returning a value, no error is thrown
}

const doItPlus = debounce(doIt, 100, { accumulate: true })

async function main() {
    const promises = [
        doItPlus('first').catch((error) => console.log('error1', error)),
        doItPlus('second').catch((error) => console.log('error2', error)),
        doItPlus('third').catch((error) => console.log('error3', error)),
    ]

    await Promise.all(promises)
}

main()
error1 TypeError: Cannot read property '0' of undefined
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Promise.all (index 0)
error2 TypeError: Cannot read property '1' of undefined
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Promise.all (index 1)
error3 TypeError: Cannot read property '2' of undefined
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Promise.all (index 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant