Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
event-loop-yielder
Advanced tools
A collection of strategies for yielding to the event loop, to avoid blocking for too long.
A collection of strategies for yielding to the event loop, to avoid blocking for too long.
npm install --save event-loop-yielder
The following functions will each make a different kind of yielder, you just call it and await its result, the yielder will decide on its own whether to actually yield to the event loop or not.
makeImmediateYielder
An immediate yielder will yield to the main thread using a polyfilled setImmediate
, which waits for microtasks, but not timeouts.
import {makeImmediateYielder} from 'event-loop-yielder';
const yielder = makeImmediateYielder ();
for ( let i = 0; i < 1000000; i++ ) {
if ( i % 100 ) { // // Yielding every 100th iteration
await yielder ();
}
runSomeComputation ();
}
makeIntervalYielder
An interval yielder will yield to the event loop after at least interval
number of milliseconds have elapsed since it last yielded.
It supports yielding via different strategies, by default it will use setTimeout
.
import {makeIntervalYielder} from 'event-loop-yielder';
const yielder = makeIntervalYielder ( 16 ); // Yield after 16ms have elapsed since the last yield
for ( let i = 0; i < 1000000; i++ ) {
await yielder (); // The yielder may or may not actually yield when you call it
runSomeComputation ();
}
makeTimeoutYielder
A timeout yielder will yield to the main thread using setTimeout
, which usually gives a lot of time for the engine/browser to do its things.
import {makeTimeoutYielder} from 'event-loop-yielder';
const yielder = makeTimeoutYielder ();
for ( let i = 0; i < 1000000; i++ ) {
if ( i % 100 ) { // // Yielding every 100th iteration
await yielder ();
}
runSomeComputation ();
}
MIT © Fabio Spampinato
FAQs
A collection of strategies for yielding to the event loop, to avoid blocking for too long.
The npm package event-loop-yielder receives a total of 20 weekly downloads. As such, event-loop-yielder popularity was classified as not popular.
We found that event-loop-yielder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.