
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
JavaScript-style timers for .NET
Library offers simple API which mimics behaviour of NodeJS/Browser functions available in JavaScript, such as
Original behaviour is closer to NodeJS (Returns objects instead of numbers, has ability to keep application running, et cetera) and is replicated as much as possible inside of the CLR
For the full guide on the package functionality, make sure to check out the docs
Install-Package JsTimers
dotnet add package JsTimers
All methods of library's public API are located inside JsTimers.TimerManager
therefore, explanations below will not contain this type as prefix to presented method
For most cases it is easier to include using static
directive in your code as shown below:
using static JsTimers.TimerManager;
To create basic timer, which will be fired once after specified delay,
use SetTimeout
method:
SetTimeout(() => {
Console.WriteLine("Hello, JsTimers!");
}, 1000);
This will issue a timeout of 1 second and then execute a given callback
All methods mentioned above actually return objects which represent timers. These objects could be assigned to a variable for further actions, such as cancelling:
Timeout timeout = SetTimeout(() => {
Console.WriteLine("This callback will not fire");
}, 1000);
ClearTimeout(timeout);
Do not use this library to time execution of actions which require
very high precision. Library runs internal loop and processes all active timers
one by one, this might sometimes cause overhead of up to 30ms
,
therefore it works fine in most cases when you build general purpose software,
but if you want to build an atomic clock with that, I have bad news for you
FAQs
JavaScript-like timer API for .NET
We found that jstimers 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.