jcoreio / async-throttle Goto Github PK
View Code? Open in Web Editor NEWthrottle async and promise-returning functions like lodash.throttle
License: MIT License
throttle async and promise-returning functions like lodash.throttle
License: MIT License
I'm using the new .cancel()
feature, but I'm getting an UnhandledRejectionWarning
in the following situation:
var asyncThrottle = require("@jcoreio/async-throttle");
const myFn = asyncThrottle(() => new Promise((resolve) => setTimeout(resolve, 10)), 1000);
(async () => {
await myFn().catch(() => {});
await myFn.cancel().catch(() => {));
console.log('canceled');
})();
Shoudn't:
const throttled = throttle(foo, 10, {
getNextArgs: ([a], [b]) => [Math.min(a, b)]
})
throttled(2)
throttled(1)
throttled(3)
// foo will be called with 1
// time passes...
throttled(4)
throttled(6)
throttled(5)
// foo will be called with 4
be:
const throttled = throttle(foo, 10, {
getNextArgs: ([a], [b]) => [Math.min(a, b)]
})
throttled(1)
throttled(2)
throttled(3)
// foo will be called with 3
// time passes...
throttled(4)
throttled(5)
throttled(6)
// foo will be called with 6
?
Hi again,
Starting with 1.3.0 I'm getting this error with each throttled call:
<rejected> TypeError: result.catch is not a function
at invoke (.../node_modules/@jcoreio/async-throttle/index.js:100:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
My usage hasn't changed and 1.2.0 and earlier work fine... maybe a check just needs to be added there? Thanks for taking a look!
I'm guessing what you're getting at is you can end up with uncaught promise exceptions... or is there something else too?
Would be good to explain properly what this package does that others don't. At present I have no idea if it will solve my problem without digging through your source code
Hey again :)
I recently switched to the official npm module, but since Babel isn't used server-side in this case, I get errors like
<rejected> Error: Cannot find module 'babel-runtime/regenerator'
Require stack:
- C:\Users\Me\AppData\Roaming\npm\node_modules\karaoke-forever\node_modules\@jcoreio\async-throttle\lib\index.js
- C:\Users\Me\AppData\Roaming\npm\node_modules\karaoke-forever\server\Library\ipc.js
- C:\Users\Me\AppData\Roaming\npm\node_modules\karaoke-forever\server\serverWorker.js
- C:\Users\Me\AppData\Roaming\npm\node_modules\karaoke-forever\server\main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\Me\AppData\Roaming\npm\node_modules\karaoke-forever\node_modules\@jcoreio\async-throttle\lib\index.js:3:20)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\karaoke-forever\\node_modules\\@jcoreio\\async-throttle\\lib\\index.js',
'C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\karaoke-forever\\server\\Library\\ipc.js',
'C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\karaoke-forever\\server\\serverWorker.js',
'C:\\Users\\Me\\AppData\\Roaming\\npm\\node_modules\\karaoke-forever\\server\\main.js'
]
FWIW, the src works fine as-is in modern Node versions (minus the type annotations of course) but I'm not sure of other ramifications. Thanks again for this library!
Similarly to lodash, it would be awesome to have a cancel
method attached to the returned function.
The implemention would cancel any pending timeout as well as returning a the ongoing promise, so that it can be awaited.
Every time i try to call throttle like it said in example, it throws an error:
Uncaught (in promise) TypeError: async_throttle_1.throttle is not a function
Hello,
I was wondering if you could expose a .d.ts
file, this should be generatable from your flow typings.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.