Example
Example copied to clipboard
Subscribe timer
async () => {
setInterval(() => {
const stats = lib.resmon.getStatistics();
context.client.emit('example/resmon', stats);
}, config.resmon.interval);
return { subscribed: 'resmon' };
};
In this case, if we reload page, we have error:
10:37:21 W3 error TypeError: Cannot read property 'connection' of undefined
Client.emit (/node_modules/metacom/lib/channel.js:75:18)
Timeout._onTimeout (/application/api/example.1/subscribe.js:10:20)
listOnTimeout (internal/timers.js:554:17)
processTimers (internal/timers.js:497:7)
We can add try/catch to fix timer:
async () => {
const timer = setInterval(() => {
const stats = lib.resmon.getStatistics();
try { context.client.emit('example/resmon', stats); }
catch (e) { clearInterval(timer) };
}, config.resmon.interval);
return { subscribed: 'resmon' };
};
Yes, you can make PR with this quick patch and issue to implement 'disconnect' event and example how to use this event with subscription.
You didn't provide file names and location, I can't reproduce this, and even understand. I think this is not relevant as of today, a lot has already changed, release 3.0 is coming next week, try to use it.