
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
tick-promise
Advanced tools
There are cases that process nextTick needs to be used in ES 2017 async functions:
const nextTick = require('tick-promise');
(async () => {
// Some code that uses process.nextTick
await nextTick();
// Do things after process.nextTick
})()
npm install tick-promise
For an example we'll use 2 nice node modules, prompts
for retrieving user input and simple-node-logger
to create our logs:
const prompts = require('prompts');
const log = require('simple-node-logger').createSimpleLogger();
(async () => {
log.info('Asking user age');
const response = await prompts({
type: 'number',
name: 'value',
message: 'How old are you?',
validate: value => value < 18 ? `Nightclub is 18+ only` : true
});
console.log(response); // => { value: 24 }
})();
If we execute this, we'll get something like this:
We can see that the logger text output is next to the prompt output, not good. That happens because simple-node-logger
uses process.nextTick
to do the output. In order to avoid this, we need to create a promise wrapper for process.nextTick
and use it after the logger and before the prompt:
const prompts = require('prompts');
const log = require('simple-node-logger').createSimpleLogger();
const nextTick = require('tick-promise');
(async () => {
log.info('Asking user age');
await nextTick();
const response = await prompts({
type: 'number',
name: 'value',
message: 'How old are you?',
validate: value => value < 18 ? `Nightclub is 18+ only` : true
});
console.log(response); // => { value: 24 }
})();
Now we get the proper output result 👍
FAQs
A promise wrapper for process nextTick
The npm package tick-promise receives a total of 776 weekly downloads. As such, tick-promise popularity was classified as not popular.
We found that tick-promise demonstrated a not healthy version release cadence and project activity because the last version was released 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.