simulate-promise

Crates.iosimulate-promise
lib.rssimulate-promise
version1.0.0
sourcesrc
created_at2023-07-12 02:05:27.351953
updated_at2023-07-12 02:13:02.630315
descriptionsimulate promise implementation for rust
homepage
repositoryhttps://github.com/Shcarp/rs-promise.git
max_upload_size
id914234
size5,215
Shcarp (Shcarp)

documentation

README

rs-promise

A simple promise implementation in rust

Usage

#[tokio::test]
    async fn test() {
        let promise = Promise::<String>::new();
        let mut promise_clone = promise.clone();
        let send_data = "111";
        tokio::spawn(async move {
            promise_clone.resolve(send_data.to_string()).await.unwrap();
            promise_clone.reject(send_data.to_string()).await.unwrap();
        });

        if let PromiseResult::Resolved(value) = promise.clone().await {
            assert_eq!(value, send_data);
        } else {
            panic!("error");
        }

        if let PromiseResult::Rejected(value) = promise.clone().await {
            assert_eq!(value, send_data);
        } else {
            panic!("error");
        }
    }
Commit count: 5

cargo fmt