feat(plugin): come back to this commit if you need high-performance timers

This commit is contained in:
Brooks J Rady 2021-04-27 16:05:01 +01:00
parent d2aa28ce30
commit 3d926d6c03
2 changed files with 21 additions and 7 deletions

View File

@ -462,6 +462,18 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
let mut plugin_id = 0; let mut plugin_id = 0;
let mut plugin_map = HashMap::new(); let mut plugin_map = HashMap::new();
move || loop { 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 let (event, mut err_ctx) = receive_plugin_instructions
.recv() .recv()
.expect("failed to receive event on channel"); .expect("failed to receive event on channel");
@ -510,7 +522,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
let start = instance.exports.get_function("_start").unwrap(); let start = instance.exports.get_function("_start").unwrap();
// This eventually calls the `.init()` method // This eventually calls the `.load()` method
start.call(&[]).unwrap(); start.call(&[]).unwrap();
plugin_map.insert(plugin_id, (instance, plugin_env)); plugin_map.insert(plugin_id, (instance, plugin_env));

View File

@ -1,10 +1,5 @@
use serde::Serialize; use serde::Serialize;
use std::{ use std::{collections::HashSet, path::PathBuf, process, sync::{mpsc::Sender, Arc, Mutex}, time::{Duration, Instant}};
collections::HashSet,
path::PathBuf,
process,
sync::{mpsc::Sender, Arc, Mutex},
};
use wasmer::{imports, Function, ImportObject, Store, WasmerEnv}; use wasmer::{imports, Function, ImportObject, Store, WasmerEnv};
use wasmer_wasi::WasiEnv; use wasmer_wasi::WasiEnv;
use zellij_tile::data::{Event, EventType, PluginIds}; use zellij_tile::data::{Event, EventType, PluginIds};
@ -30,6 +25,13 @@ pub struct PluginEnv {
pub send_pty_instructions: SenderWithContext<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels pub send_pty_instructions: SenderWithContext<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels
pub wasi_env: WasiEnv, pub wasi_env: WasiEnv,
pub subscriptions: Arc<Mutex<HashSet<EventType>>>, pub subscriptions: Arc<Mutex<HashSet<EventType>>>,
// FIXME: Add timers struct here! BinaryHeap?
}
struct CallbackTimer {
wake_time: Instant,
plugin_id: u32,
recurring: bool,
} }
// Plugin API --------------------------------------------------------------------------------------------------------- // Plugin API ---------------------------------------------------------------------------------------------------------