Skip to content

Commit

Permalink
Merge pull request #22 from ynqa/promkit-async/v0.1.1/main
Browse files Browse the repository at this point in the history
(promkit-async) v0.1.1
  • Loading branch information
ynqa authored May 19, 2024
2 parents fba7c2f + c2410fa commit fc8efed
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion promkit-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "promkit-async"
version = "0.1.0"
version = "0.1.1"
authors = ["ynqa <un.pensiero.vano@gmail.com>"]
edition = "2021"
description = "Async for promkit"
Expand Down
2 changes: 1 addition & 1 deletion promkit-async/examples/lazyutil/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use promkit::{

use tokio::sync::mpsc::Sender;

use promkit_async::EventBundle;
use promkit_async::event_buffer::EventBundle;

pub type Handler = fn(&[EventBundle], &mut text_editor::State, &Sender<()>) -> anyhow::Result<()>;

Expand Down
2 changes: 1 addition & 1 deletion promkit-async/examples/lazyutil/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use promkit::{pane::Pane, switch::ActiveKeySwitcher, text_editor, PaneFactory};
use futures::Future;
use tokio::sync::mpsc::Sender;

use promkit_async::{EventBundle, PaneSyncer};
use promkit_async::{event_buffer::EventBundle, PaneSyncer};

use crate::lazyutil::keymap;

Expand Down
10 changes: 5 additions & 5 deletions promkit-async/src/display_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use crossterm::terminal;
use futures::{Future, FutureExt};
use futures::Future;
use futures_timer::Delay;
use tokio::sync::mpsc::Receiver;

Expand Down Expand Up @@ -69,11 +69,11 @@ impl DisplayCoordinator {

async move {
loop {
let delay = Delay::new(delay_duration).fuse();
let delay = Delay::new(delay_duration);
futures::pin_mut!(delay);

futures::select! {
maybe_tuple = loading_activation_receiver.recv().fuse() => {
tokio::select! {
maybe_tuple = loading_activation_receiver.recv() => {
match maybe_tuple {
Some((version, index)) => {
if version > global.load(Ordering::SeqCst) {
Expand All @@ -84,7 +84,7 @@ impl DisplayCoordinator {
None => break,
}
},
maybe_triplet = indexed_pane_receiver.recv().fuse() => {
maybe_triplet = indexed_pane_receiver.recv() => {
match maybe_triplet {
Some((version, index, pane)) => {
if version >= global.load(Ordering::SeqCst) {
Expand Down
8 changes: 4 additions & 4 deletions promkit-async/src/event_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
use futures::future::{Future, FutureExt};
use futures::future::Future;
use futures_timer::Delay;
use tokio::sync::mpsc::{Receiver, Sender};

Expand Down Expand Up @@ -32,11 +32,11 @@ impl EventBuffer {

async move {
loop {
let delay = Delay::new(delay_duration).fuse();
let delay = Delay::new(delay_duration);
futures::pin_mut!(delay);

futures::select! {
maybe_event = event_receiver.recv().fuse() => {
tokio::select! {
maybe_event = event_receiver.recv() => {
if let Some(event) = maybe_event {
buffer.push(event);
} else {
Expand Down
21 changes: 10 additions & 11 deletions promkit-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::Duration,
};

use futures::{future::FutureExt, stream::StreamExt, Future};
use futures::{stream::StreamExt, Future};

use tokio::sync::mpsc::Receiver;

Expand All @@ -22,12 +22,11 @@ use promkit::{
terminal::Terminal,
};

mod event_buffer;
use event_buffer::EventBuffer;
pub use event_buffer::EventBundle;
mod resize_debounce;
pub mod event_buffer;
use event_buffer::{EventBuffer, EventBundle};
pub mod resize_debounce;
use resize_debounce::ResizeDebounce;
mod display_coordinator;
pub mod display_coordinator;
use display_coordinator::DisplayCoordinator;

pub trait PaneSyncer: promkit::Finalizer {
Expand Down Expand Up @@ -100,8 +99,8 @@ impl<T: PaneSyncer> Prompt<T> {
let version = Arc::new(AtomicUsize::new(1));

loop {
futures::select! {
maybe_event = stream.next().fuse() => {
tokio::select! {
maybe_event = stream.next() => {
if let Some(Ok(event)) = maybe_event {
match event {
Event::Resize(width, height) => {
Expand All @@ -113,18 +112,18 @@ impl<T: PaneSyncer> Prompt<T> {
}
}
},
maybe_debounced_resize = debounced_resize_receiver.recv().fuse() => {
maybe_debounced_resize = debounced_resize_receiver.recv() => {
if let Some((width, height)) = maybe_debounced_resize {
size = (width, height);
}
},
maybe_event_buffer = event_buffer_receiver.recv().fuse() => {
maybe_event_buffer = event_buffer_receiver.recv() => {
if let Some(event_buffer) = maybe_event_buffer {
let next = version.fetch_add(1, Ordering::SeqCst);
self.renderer.sync(next, &event_buffer, size.0, size.1).await?;
}
},
maybe_fin = fin_receiver.recv().fuse() => {
maybe_fin = fin_receiver.recv() => {
if maybe_fin.is_some() {
break;
}
Expand Down
8 changes: 4 additions & 4 deletions promkit-async/src/resize_debounce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use futures::future::{Future, FutureExt};
use futures::future::Future;
use futures_timer::Delay;

use tokio::sync::mpsc::{Receiver, Sender};
Expand All @@ -23,11 +23,11 @@ impl ResizeDebounce {
async move {
let mut last_event: Option<(u16, u16)> = None;
loop {
let delay = Delay::new(delay_duration).fuse();
let delay = Delay::new(delay_duration);
futures::pin_mut!(delay);

futures::select! {
resize_opt = resize_receiver.recv().fuse() => {
tokio::select! {
resize_opt = resize_receiver.recv() => {
if let Some(event) = resize_opt {
last_event = Some(event);
} else {
Expand Down

0 comments on commit fc8efed

Please sign in to comment.