File size: 963 Bytes
61d39e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { kv } = extension.import('data');
const { sleep } = extension.import('utilities');

// "kv" is load ready to use before the 'init' event is fired.
extension.on('init', async () => {
    kv.set('example-kv-key', 'example-kv-value');

    console.log('kv key has', await kv.get('example-kv-key'));

    await kv.expire({
        key: 'example-kv-key',
        ttl: 1000 * 60, // 1 minute
    });

    // This AIIFE demonstrates how "kv.expire" works.
    // We cannot simply "await" this - otherwise we block init!
    (async () => {
        // wait for 30 seconds...
        await sleep(30 * 1000);

        console.log('kv key still has value', await kv.get('example-kv-key'));

        // wait for 30 more seconds
        await sleep(30 * 1000);
        // and just a little bit longer
        // await sleep(100);

        console.log('kv key should no longer have the value', await kv.get('example-kv-key'));
    })();
});