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.
Perform async work synchronously in Node.js using a separate process with first-class TypeScript support
The synckit npm package allows for executing asynchronous tasks synchronously using worker threads or child processes. It is designed to offload heavy computation or I/O-bound tasks without blocking the main thread, thus enabling a synchronous-like coding style while maintaining non-blocking behavior.
Running asynchronous tasks synchronously
This feature allows you to run an asynchronous task inside a worker thread and wait for the result synchronously. The 'worker.js' file should export an async function that will be executed with the provided arguments.
const { runAsWorkerThread } = require('synckit');
const result = runAsWorkerThread('./worker.js', ...args);
Creating a synchronous API from asynchronous functions
With this feature, you can create a synchronous version of an asynchronous function. The 'async-fn.js' file should export an async function that will be executed with the provided arguments, and the result will be returned synchronously.
const { createSyncFn } = require('synckit');
const syncFn = createSyncFn('./async-fn.js');
const result = syncFn(...args);
Deasync turns asynchronous functions into synchronous by blocking the event loop. It is similar to synckit in providing a way to write synchronous-style code, but it does so by pausing the event loop, which can lead to performance issues and is not recommended for production use.
The 'threads' package is used to manage and work with Web Workers and worker threads in Node.js. It offers similar functionality to synckit by allowing asynchronous tasks to be offloaded to separate threads, but it provides a more comprehensive API for managing those threads.
Workerpool is a package for managing a pool of workers and running tasks in parallel. It is similar to synckit in that it uses worker threads to execute tasks asynchronously, but it focuses on managing a pool of workers and distributing tasks among them for parallel processing.
Perform async work synchronously in Node.js using a separate process with first-class TypeScript support
# yarn
yarn add synckit
# npm
npm i synckit
// runner.js
import { createSyncFn } from 'synckit'
// the worker path must be absolute
const syncFn = createSyncFn(require.resolve('./worker'))
// do whatever you want, you will get the result synchronously!
const result = syncFn(...args)
// worker.js
import { runAsWorker } from 'synckit'
runAsWorker(async (...args) => {
// do expensive work
// but you must make sure the `result` is serializable by `JSON.stringify`
return result
})
Detailed changes for each release are documented in CHANGELOG.md.
FAQs
Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.
The npm package synckit receives a total of 6,610,449 weekly downloads. As such, synckit popularity was classified as popular.
We found that synckit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.