Git Product home page Git Product logo

local-sync's Introduction

local-sync

Local-sync is a crate providing data structures for sync within the local thread.

mpsc

Mpsc includes bounded and unbounded channel.

Once Cell

Once cell like once in golang.

Oneshot

Oneshot channel which can be send and receive data only one time. Also, it can be used as a notification method.

Semaphore

You can async wait permits and add permits with Semaphore.

Licenses

Local-sync is licensed under the MIT license or Apache license.

During developing we referenced a lot from Tokio. We would like to thank the authors of the projects.

local-sync's People

Contributors

ihciah avatar wireless4024 avatar

Stargazers

 avatar Huayu Zhang avatar feiyunnt avatar Emily Dietrich avatar Nam Se Hyun avatar Rogério da Silva Yokomizo avatar Shabbir Hasan avatar Andy avatar kkocdko avatar  avatar Four Hu avatar Duarte Nunes avatar Anthony Griffon avatar Andrew Hlynskyi avatar Nguyen Huu Anh Tuan avatar Pop avatar wh7f avatar LingFeng avatar  avatar Yi avatar tsingson avatar Zheng Li avatar Suraj avatar Tiago Carvalho avatar 郭 avatar Zhanhui Li avatar Jackson Xu avatar Mutalisk avatar Kaizhao Zhang avatar  avatar LIU JIE avatar Max Meldrum avatar Will Brown avatar Anish Mukherjee avatar ℤiλ∀ avatar Alex Chi Z. avatar  avatar

Watchers

 avatar  avatar

local-sync's Issues

Semantics of Rx::recv when its senders are all dropped

IMHO, mpsc Rx::recv should return None if all the Tx have been dropped.
In the following test cases, tokio passes while the local-sync blocks for ever.

#[monoio::test(enable_timer = true)]
    async fn test_local_sync_mpsc() {
        env_logger::try_init().unwrap();
        let (tx, mut rx) = local_sync::mpsc::unbounded::channel::<()>();
        let handle = monoio::spawn(async move {
            loop {
                trace!("Awaiting rx");
                match rx.recv().await {
                    Some(()) => {
                        trace!("Got a rx event");
                        continue;
                    }

                    None => {
                        trace!("Received None");
                        break;
                    }
                }
            }
        });

        let handle2 = monoio::spawn(async move {
            tx.send(()).unwrap();
            monoio::time::sleep(std::time::Duration::from_secs(1)).await;
            drop(tx);
            trace!("dropped tx");
        });

        handle2.await;
        handle.await;
    }

    #[monoio::test(enable_timer = true)]
    async fn test_tokio_mpsc() {
        env_logger::try_init().unwrap();
        let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<()>();
        let handle = monoio::spawn(async move {
            loop {
                trace!("Awaiting rx");
                match rx.recv().await {
                    Some(()) => {
                        trace!("Got a rx event");
                        continue;
                    }

                    None => {
                        trace!("Received None");
                        break;
                    }
                }
            }
        });

        let handle2 = monoio::spawn(async move {
            tx.send(()).unwrap();
            monoio::time::sleep(std::time::Duration::from_secs(1)).await;
            drop(tx);
            trace!("dropped tx");
        });

        handle2.await;
        handle.await;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.