Comments (5)
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.
Please reopen if the error persists 😃
from bottleneck.
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.
I'll see if I can improve the Readme!
from bottleneck.
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 returnPromise.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)
- Support for node-redis v4
- Invalid job status RECEIVED, expected DONE HOT 1
- task.apply is not a function
- Any correct ways to do rate limit 1000 per hour?
- `light.d.ts` not published in npm package
- Throw error for invalid settings
- Would it be possible to add a reset() method to clear state on local instances? HOT 1
- ReplyError: ERR SETTINGS_KEY_NOT_FOUND when use in Clustering mode with Redis 7.x HOT 8
- Is bottleneck still maintained? HOT 11
- recovering for a crashed service using redis
- bottleneck lost tracing data when using reservoir options
- Redis errors with ReplyError: ERR UNKOWN_CLIENT HOT 7
- dynamic schedule / retry HOT 3
- Long delay in Bottleneck.schedule execution in a distributed env HOT 1
- Is there a way to pass different options for limiters within the same group?
- Is there a way to read and write the reservoir for a given limiter?
- Long-lasting limiters with matching cardinality to app's users
- ERR SETTINGS_KEY_NOT_FOUND with redis 7.0.7 HOT 11
- user_script:201: attempt to compare number with nil
- Warning from vite about using eval
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bottleneck.