-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.js
More file actions
45 lines (36 loc) · 1.07 KB
/
examples.js
File metadata and controls
45 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// MicroCODE: define this module's name for our 'mcode-package' package
const MODULE_NAME = 'examples.js';
const mcode = require('./index.js');
// Make the MicroCODE functions available globally, from a single read-only object
global.mcode = mcode;
async function showExample()
{
// wait for the cache to be ready...
const maxRetries = 30;
let retries = 0;
while (!mcode.redisReady && retries < maxRetries)
{
mcode.log('Waiting for cache to be ready...', MODULE_NAME);
await new Promise(resolve => setTimeout(resolve, 1000));
retries++;
}
if (!mcode.redisReady)
{
throw new Error('Cache not ready after waiting for 30 seconds.');
}
else
{
mcode.log('Cache is ready!', MODULE_NAME);
}
// show the 'bundled' mcode namespace...
mcode.info({mcode: mcode}, MODULE_NAME);
// Demo logging...
mcode.done('Hello from the mcode-package module!', MODULE_NAME);
}
// run the tests
showExample();
// exit the process after the demo is done...
setTimeout(() =>
{
process.exit(0);
}, 2000);