Socket
Socket
Sign inDemoInstall

waitasecond

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waitasecond - npm Package Compare versions

Comparing version 1.8.2 to 1.8.5

1

dist/functions/forAllImagesInElement.js

@@ -9,2 +9,3 @@ "use strict";

TODO: !!! Universal for every loadable think
TODO: !!! Also start new wait when new images appears / disappears during the wait
TODO: Verbose mode for console.info

@@ -11,0 +12,0 @@ */

5

dist/functions/forValueDefined.d.ts

@@ -1,3 +0,2 @@

declare type IAwaitable<T> = T | Promise<T>;
export declare function forValueDefined<T>(getValue: () => IAwaitable<T | undefined | null>, waiter?: () => Promise<void>, limit?: number): Promise<T>;
export {};
import { AsyncOrSync } from 'ts-essentials';
export declare function forValueDefined<T>(getValue: () => AsyncOrSync<T | undefined | null>, waiter?: () => Promise<void>, limit?: number): Promise<T>;
{
"name": "waitasecond",
"version": "1.8.2",
"version": "1.8.5",
"description": "Simple tool library for the waiting using Promises.",

@@ -43,6 +43,6 @@ "main": "dist/main.js",

"@types/express": "^4.17.13",
"@types/jest": "^24.0.13",
"@types/jest": "^27.0.1",
"@types/serve-index": "^1.9.1",
"codecov": "^3.5.0",
"cypress": "^8.3.1",
"codecov": "^3.8.3",
"cypress": "^8.4.0",
"cypress-image-snapshot": "^4.0.1",

@@ -52,17 +52,18 @@ "express": "^4.17.1",

"glob-promise": "^4.2.0",
"jest": "^24.8.0",
"onchange": "^3.3.0",
"jest": "^27.2.0",
"onchange": "^7.1.0",
"open": "^8.2.1",
"organize-imports-cli": "^0.8.0",
"prettier": "github:prettier/prettier",
"prettier": "^2.4.0",
"serve-index": "^1.9.1",
"serve-static": "^1.14.1",
"ts-jest": "^24.0.2",
"ts-node": "^9.0.0",
"ts-essentials": "^8.1.0",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8",
"tslint": "^5.17.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.21.9",
"typescript": "^4.0.3"
"typedoc": "^0.22.3",
"typescript": "^4.4.3"
}
}
# ⏰ Waitasecond
Waitasecond is an extremely simple and elegant tool for using **working with async code and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**. It is usable by browser, worker and node environment and fully typed.
Wait a second is an extremely simple and elegant tool for using **working with async code and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**. It is usable by browser, worker, and node environment and fully typed.

@@ -15,3 +15,3 @@ # 🔥 Install

In JavaScript there is very elegant syntax to write asynchronous code with **async/await**. Every internal function and library is heading forward to be compatible with Promises and deprecating its old callback type.
In JavaScript, there is an elegant way how to write asynchronous code with **async/await** syntax construct. Every internal function and library is heading forward to be compatible with Promises and deprecating its old callback type.
But there are some **relicts from [callback hell](http://callbackhell.com/)** like **setTimeout, requestAnimationFrame,...**. Waitasecond has motivation to turn this into elegant syntax:

@@ -22,5 +22,5 @@

console.log(`⏳ This is logged immediatelly.`);
console.log(`⏳ This is logged immediately.`);
await forTime(500);
console.log(`⌛ And this after 500 miliseconds.`);
console.log(`⌛ And this after 500 milliseconds.`);
await forTime(666);

@@ -30,2 +30,5 @@ console.log(`😈 Wow, I have escaped from callback hell`);

[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forTime)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forTime.ts)
## 🕧 Await forImmediate _([setImmediate](https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate) equivalent)_

@@ -59,5 +62,8 @@

_Note: Despite window.setImmediate is non-standard feature and it is not working in node, function **forImmediate is working in all environments**_
_Note: If you want to use equivalent of [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval), see [https://rxjs.dev/api/index/function/interval)._
_Note: Despite window.setImmediate is a non-standard feature and it is not working in node, function **forImmediate is working in all environments**_
_Note: If you want to use an equivalent of [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval), see [RxJS interval](https://rxjs.dev/api/index/function/interval)._
[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forImmediate)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forImmediate.ts)
## 🕐 Await forAnimationFrame _([requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) equivalent)_

@@ -71,3 +77,3 @@

while (
true /* ← Normally this would be 💩 code but with forAnimationFrame it is nicer syntax version of requestAnimationFrame*/
true /* ← Normally, this would be 💩 code, but with forAnimationFrame it is a nicer syntax version of requestAnimationFrame*/
) {

@@ -81,7 +87,10 @@ const now = await forAnimationFrame();

_Note: This is working only in browser environment._
_Note: This is working only in a browser environment._
[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forAnimationFrame)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forAnimationFrame.ts)
## 🕜 Await forEver
Never resolves or rejects. It is elegant way to test what happen if some part of async code stucks (for example some fetch call).
forEver function returns a promise which never resolves or rejects. It is an elegant way to test what happened if some part of asynchronous code stuck (for example, fetch call).

@@ -95,4 +104,10 @@ ```typescript

[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forEver)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forEver.ts)
## 🕑 Await forTimeSynced
**forTimeSynced** is an ideal way how to do periodical ticking in an unstable environment.
For example, if you want to run a process every 10 minutes on a server, but PM2 is restarting a server unexpectedly.
```typescript

@@ -109,2 +124,5 @@ import { forTimeSynced } from 'waitasecond';

[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forTimeSynced)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forTimeSynced.ts)
## 🕝 Await forValueDefined

@@ -115,5 +133,10 @@

// TODO: !!!
const firstName = forValueDefined(() => data.firstName);
```
_Note: This is not definitely the ideal way how to wait for things. But it can be helpful if you want to "observe" some mutating object which do not support it natively._
[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forValueDefined)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forValueDefined.ts)
## 🕒 Await forAllImagesInElement

@@ -124,7 +147,15 @@

// TODO: !!!
await forAllImagesInElement(document.body);
console.log(`🖼️ Now I can be sure that all images in body are loaded.`);
// ...
await renderToPdf(document.body);
// ...
```
[📖Documentation](https://hejny.github.io/waitasecond/modules.html#forAllImagesInElement)
[💻Code](https://github.com/hejny/waitasecond/blob/main/src/functions/forAllImagesInElement.ts)
# 🖋️ Contributing
I am opened to your pull requests, feedback, suggestions and donations :) . Contact to me is on my [personal page](https://www.pavolhejny.com)
I am opened to your pull requests, feedback, suggestions, and donations. Contact to me is on my [personal page](https://www.pavolhejny.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc