Skip to content

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

@PieterScheffers

Description

@PieterScheffers

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions