Initial commit: Example Plugin 3 with async operations

This commit is contained in:
2026-04-17 03:00:27 +10:00
commit 3bb85bd101
3 changed files with 79 additions and 0 deletions

37
index.js Normal file
View File

@@ -0,0 +1,37 @@
/**
* Example Plugin 3 - Async Operations & Storage
*/
let dataStore = {};
let intervalId = null;
export async function activate(context) {
context.log('Example Plugin 3 activated!');
// Register async data hook
context.registerHook('fetch-data', async (key) => {
context.log(`Fetching data for key: ${key}`);
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async operation
return dataStore[key] || null;
});
// Register data storage hook
context.registerHook('store-data', async (key, value) => {
context.log(`Storing data: ${key} = ${value}`);
dataStore[key] = value;
return true;
});
// Periodic status report
intervalId = setInterval(() => {
const keys = Object.keys(dataStore).length;
context.log(`Storage status: ${keys} entries`);
}, 30000);
}
export async function deactivate(context) {
if (intervalId) {
clearInterval(intervalId);
}
context.log('Example Plugin 3 deactivated!');
}