aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-04-27 16:05:01 +0100
committerBrooks J Rady <b.j.rady@gmail.com>2021-04-27 16:05:01 +0100
commit3d926d6c03f0eaf53d86b48b2ea9d26866f8618e (patch)
tree9c2961315b06219ec1ebab0fc81eb636d82708d3 /src
parentchore(changelog): new plugin API (diff)
downloadsl0ppij-3d926d6c03f0eaf53d86b48b2ea9d26866f8618e.tar.gz
sl0ppij-3d926d6c03f0eaf53d86b48b2ea9d26866f8618e.tar.xz
sl0ppij-3d926d6c03f0eaf53d86b48b2ea9d26866f8618e.zip
feat(plugin): come back to this commit if you need high-performance timers
Diffstat (limited to 'src')
-rw-r--r--src/common/mod.rs14
-rw-r--r--src/common/wasm_vm.rs14
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<dyn OsApi>, 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<dyn OsApi>, 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<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels
pub wasi_env: WasiEnv,
pub subscriptions: Arc<Mutex<HashSet<EventType>>>,
+ // FIXME: Add timers struct here! BinaryHeap?
+}
+
+struct CallbackTimer {
+ wake_time: Instant,
+ plugin_id: u32,
+ recurring: bool,
}
// Plugin API ---------------------------------------------------------------------------------------------------------