zellij-runtime

Crates.iozellij-runtime
lib.rszellij-runtime
version0.0.4
created_at2025-10-09 17:26:48.057195+00
updated_at2025-10-13 18:48:02.401322+00
descriptionAn async runtime for zellij plugins
homepage
repositoryhttps://github.com/Borwe/zellij_runtime/
max_upload_size
id1875963
size125,744
Brian Orwe (Borwe)

documentation

README

ZELLIJ RUNTIME

An async runtime to be used inside Zellij Plugins

This crate provides to way to have async rust capabilities while inside a zellij plugin for plugin developers, it is 3rd party and therefore not officially directly associated by the zellij team.

Note:

This isn't using tokio, or async-std, it's a custom runtime specifically for zellij, if intending to use crates you might have to provide your own reactor with them, or extend this crates reactor to support those crates.

Usage

For starters all the functions for usage for async functionality are in the zellij_runtime::prelude::* space, but you can explore others exported by the crate, be careful though, read the docs to what they do and post an issue on the repo if not clear, or if you have suggestions for making it more clear.

Before function start properly, you'll need to initialize the plugin state with zellij_runtim::prelude::register_async_plugin macro instead of as you would have before with register_plugin macro from the zellij_tile crate used for plugin.

An example

To first create an async task call zellij_runtime::prelude::spawn as shown bellow:

/// Spawn a new async activity.
/// If None is passed as @id parameter then it will be
/// spawned everytime the call comes as a unique async task.
/// If you want to only spawn it once, then give it a single id,
/// by calling the function zellij_runtime::prelude::get_id(),
/// which returns a unique id, and means that runtime will check if a task
/// with such an id exists or not, if it does then the task is added to the queue
/// else nothing happens, even if the _this_ get's called over and over with
/// the same @id value eg:

self.id = get_id();

spawn(self.id, async {
      for i in 0..10 {
          eprintln!("YO-{i}");
          sleep(Duration::from_secs(5)).await;
      }
});

///  remember to cache the id from get_id() to some state, otherwise just calling get_id(),
///  and passing it directly will be the same as passing None, as you will be passing a new
///  id everytime.

This function creates an async task and stores it to be made progress evertime the update function get's called, that is when the reactor also wakes up sleeping tasks too.

For more examples checkout this directory

Extra Async functions available or to be made available for ease of use inside zellij_runtime::prelude::

  • get_id => get custom id to be used for spawning tasks with spawn
  • register_async_plugin => macro to register a plugin as being async
  • sleep => Asynchronously sleep without blocking async task
  • spawn => Spawn a task
  • spawn_in => spawn a async concurrent task, that can return a value that implements Clone trait
  • call_render => Make the state get rendered before going ahead to next procedure
  • listen_event => Not implmented yet, a way to asynchronously listen for events
  • listen_pipe => Not implmented yet, a way to asynchronously listen for piped messages
  • web_request => Not implemented yet, a way to asynchronously make web request
  • read_file => Not implemented yet, a way to asynchronously read a file
  • write_file => Not implemented yet, a way to asynchronously write a file
  • ...more might be added
Commit count: 0

cargo fmt