Coder Social home page Coder Social logo

Comments (5)

SGrondin avatar SGrondin commented on May 17, 2024

It's not an issue with Node 9.7.1, your code will fail on any version of Node.

From the README:

Simply put, schedule takes a function Fn and a list of arguments. Fn must return a promise. schedule returns a promise that will be executed according to the rate limits.

The function you are giving to .schedule() does not return a Promise, it returns a String.

Try this instead:

limiter.schedule(() => Promise.resolve('im the call'))
  .then((result) => { console.log('handle result', result) });

Output:

handle result im the call

Future versions of Bottleneck might wrap your non-Promise values into a Promise, or at least give a better error message.

from bottleneck.

SGrondin avatar SGrondin commented on May 17, 2024

Please reopen if the error persists 😃

from bottleneck.

alangibson avatar alangibson commented on May 17, 2024

The dangers of late night programming 🤦‍♂️ I think just including that use of Promise in one of the examples in the README would probably be enough for people like me that tend to read the code and skim the prose.

from bottleneck.

SGrondin avatar SGrondin commented on May 17, 2024

I'll see if I can improve the Readme!

from bottleneck.

SGrondin avatar SGrondin commented on May 17, 2024

EDIT: It's no more required to return a Promise.

With the newly released 2.2.1 you'll get the following error message:

The function given to schedule() did not return a Promise. You may need to return Promise.resolve(data). You returned: This is a string (string)'

I've also added this to the Readme:


If your function does not return a promise, it needs to use Promise.resolve like so:

// GOOD
limiter.schedule(() => Promise.resolve("This is a string"))
.then(data => console.log(data));

// INCORRECT!
limiter.schedule(() => "This is a string")
.then(data => console.log(data));

from bottleneck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.