From 3d926d6c03f0eaf53d86b48b2ea9d26866f8618e Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 27 Apr 2021 16:05:01 +0100 Subject: [PATCH] feat(plugin): come back to this commit if you need high-performance timers --- src/common/mod.rs | 14 +++++++++++++- src/common/wasm_vm.rs | 14 ++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index d525a3fe..2388a162 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -462,6 +462,18 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let mut plugin_id = 0; let mut plugin_map = HashMap::new(); move || loop { + // BLUEPRINT: + /* next = binheap.get_timer(); // peek + let event = if let Some(time) = next { + // match for the right timeout error here... + if let Some(event) = chan.recv_timeout(time) { + event + } else { + continue + } + } else { + ch.recv().unwrap() + } */ let (event, mut err_ctx) = receive_plugin_instructions .recv() .expect("failed to receive event on channel"); @@ -510,7 +522,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let start = instance.exports.get_function("_start").unwrap(); - // This eventually calls the `.init()` method + // This eventually calls the `.load()` method start.call(&[]).unwrap(); plugin_map.insert(plugin_id, (instance, plugin_env)); diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index e8990e86..6d31a6bb 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -1,10 +1,5 @@ use serde::Serialize; -use std::{ - collections::HashSet, - path::PathBuf, - process, - sync::{mpsc::Sender, Arc, Mutex}, -}; +use std::{collections::HashSet, path::PathBuf, process, sync::{mpsc::Sender, Arc, Mutex}, time::{Duration, Instant}}; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer_wasi::WasiEnv; use zellij_tile::data::{Event, EventType, PluginIds}; @@ -30,6 +25,13 @@ pub struct PluginEnv { pub send_pty_instructions: SenderWithContext, // FIXME: This should be a big bundle of all of the channels pub wasi_env: WasiEnv, pub subscriptions: Arc>>, + // FIXME: Add timers struct here! BinaryHeap? +} + +struct CallbackTimer { + wake_time: Instant, + plugin_id: u32, + recurring: bool, } // Plugin API ---------------------------------------------------------------------------------------------------------