waiit 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ wait(ms?: number): Promise<void>
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
+
### In Code
|
|
36
|
+
|
|
35
37
|
```js
|
|
36
38
|
// CommonJS
|
|
37
39
|
const wait = require('waiit');
|
|
@@ -43,45 +45,66 @@ import wait from 'waiit';
|
|
|
43
45
|
import wait from 'https://unpkg.com/waiit/app.js';
|
|
44
46
|
```
|
|
45
47
|
|
|
48
|
+
**Basic examples:**
|
|
46
49
|
```js
|
|
47
|
-
await wait(2000); //
|
|
48
|
-
await wait();
|
|
50
|
+
await wait(2000); // Pause for 2 seconds
|
|
51
|
+
await wait(500); // Pause for 500ms
|
|
52
|
+
await wait(); // Continue immediately (0ms)
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
**Retry with delay:**
|
|
52
56
|
```js
|
|
53
57
|
async function fetchWithRetry(url, retries = 3) {
|
|
54
58
|
for (let i = 0; i < retries; i++) {
|
|
55
59
|
try {
|
|
56
60
|
return await fetch(url);
|
|
57
61
|
} catch (e) {
|
|
58
|
-
if (i < retries - 1)
|
|
62
|
+
if (i < retries - 1) {
|
|
63
|
+
console.log(`Retry ${i + 1}...`);
|
|
64
|
+
await wait(1000); // Wait 1s between retries
|
|
65
|
+
}
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
|
-
throw new Error('
|
|
68
|
+
throw new Error('Max retries reached');
|
|
62
69
|
}
|
|
63
70
|
```
|
|
64
71
|
|
|
65
|
-
|
|
72
|
+
**Sequential execution:**
|
|
66
73
|
```js
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
console.log('Starting...');
|
|
75
|
+
await wait(1000);
|
|
76
|
+
console.log('After 1 second');
|
|
77
|
+
await wait(2000);
|
|
78
|
+
console.log('After 3 seconds total');
|
|
71
79
|
```
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
### In Terminal (CLI)
|
|
74
82
|
|
|
75
83
|
```bash
|
|
76
|
-
# Via npx
|
|
77
|
-
npx waiit 2000 # Wait 2 seconds
|
|
84
|
+
# Via npx (no install needed)
|
|
85
|
+
npx waiit 2000 # Wait 2 seconds, then exit
|
|
86
|
+
echo "Done!"
|
|
78
87
|
|
|
79
88
|
# Or install globally
|
|
80
89
|
npm i -g waiit
|
|
81
|
-
waiit 3000
|
|
82
|
-
|
|
90
|
+
waiit 3000 && echo "3 seconds passed"
|
|
91
|
+
|
|
92
|
+
# Use in shell scripts
|
|
93
|
+
echo "Starting..."
|
|
94
|
+
waiit 1000
|
|
95
|
+
echo "Finished"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Shell script example:**
|
|
99
|
+
```bash
|
|
100
|
+
#!/bin/bash
|
|
101
|
+
echo "Build starting..."
|
|
102
|
+
npm run build
|
|
103
|
+
waiit 2000 # Give time for build artifacts to settle
|
|
104
|
+
echo "Deploying..."
|
|
105
|
+
npm run deploy
|
|
83
106
|
```
|
|
84
107
|
|
|
85
108
|
## License
|
|
86
109
|
|
|
87
|
-
[MIT](LICENSE) © Raju Dhami
|
|
110
|
+
[MIT](LICENSE) © [Raju Dhami](https://github.com/Raju)
|