3use crate::compositor::Compositor;
5use futures_util::future::{self, BoxFuture, Future, FutureExt};
6use futures_util::stream::{FuturesUnordered, StreamExt};
8pub type Callback = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;
9pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
12 pub future: BoxFuture<'static, anyhow::Result<Option<Callback>>>,
13 /// Do we need to wait for this job to finish before exiting?
19 pub futures: FuturesUnordered<JobFuture>,
20 /// These are the ones that need to complete before we exit.
21 pub wait_futures: FuturesUnordered<JobFuture>,
25 pub fn new<F: Future<Output = anyhow::Result<()>> + Send + 'static>(f: F) -> Job {
27 future: f.map(|r| r.map(|()| None)).boxed(),
32 pub fn with_callback<F: Future<Output = anyhow::Result<Callback>> + Send + 'static>(
36 future: f.map(|r| r.map(Some)).boxed(),
41 pub fn wait_before_exiting(mut self) -> Job {
48 pub fn new() -> Jobs {
52 pub fn spawn<F: Future<Output = anyhow::Result<()>> + Send + 'static>(&mut self, f: F) {
53 self.add(Job::new(f));
56 pub fn callback<F: Future<Output = anyhow::Result<Callback>> + Send + 'static>(
60 self.add(Job::with_callback(f));
63 pub fn handle_callback(
66 compositor: &mut Compositor,
67 call: anyhow::Result<Option<Callback>>,
72 call(editor, compositor);
75 editor.set_error(format!("Async job failed: {}", e));
80 pub async fn next_job(&mut self) -> Option<anyhow::Result<Option<Callback>>> {
82 event = self.futures.next() => { event }
83 event = self.wait_futures.next() => { event }
87 pub fn add(&mut self, j: Job) {
89 self.wait_futures.push(j.future);
91 self.futures.push(j.future);
95 /// Blocks until all the jobs that need to be waited on are done.
96 pub fn finish(&mut self) {
97 let wait_futures = std::mem::take(&mut self.wait_futures);
98 helix_lsp::block_on(wait_futures.for_each(|_| future::ready(())));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list