Initial commit: Example Plugin 3 with async operations
This commit is contained in:
37
index.js
Normal file
37
index.js
Normal 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!');
|
||||
}
|
||||
Reference in New Issue
Block a user