Giter Site home page Giter Site logo

Comments (6)

DirtyHairy avatar DirtyHairy commented on June 9, 2024 2

Published.

from async-mutex.

DirtyHairy avatar DirtyHairy commented on June 9, 2024

Hi Joe!

Thanks alot for the kind words šŸ˜ I like the idea of adding a semaphore implementation. I've been planning on overhauling the library for some time now anyway, and extending it to a semaphore with Mutex as a special case on top of it sounds like a good plan. If you can wait for this for another week or so, I'll go for it.

Cheers
-Christian

from async-mutex.

joerick avatar joerick commented on June 9, 2024

Thanks! I also came across this - https://github.com/notenoughneon/await-semaphore - but it seems more Node-centric. I'm currently using an adapted version of it in my app as I needed to get something working for now. Could be useful for inspiration!

from async-mutex.

DirtyHairy avatar DirtyHairy commented on June 9, 2024

Done. I still have to update the documentation and do a release, but I have overhauled the library and added a Semaphore and a corresponding SemaphoreInterface.

A semaphore starts out with a positive definite value that is decremented each time it is locked and incremented on release. Once it has reached zero acquire will block until it has been incremented again. The API is pretty similar to Mutex --- acquire will return a tuple of the current semaphore value and the release callback, and runExclusive will pass on the current semaphore value to the callback. By definition, the values returned will be within 1 .. N where N is the initial value of the semaphore.

I'll do a proper release with updated documentation in the next days, but if you feel adventurous... šŸ˜

from async-mutex.

joerick avatar joerick commented on June 9, 2024

Nice! One note - I think for a semaphore runExclusive could be the wrong name - it's not exclusively running. Maybe just run would be okay?

from async-mutex.

DirtyHairy avatar DirtyHairy commented on June 9, 2024

I had the same inclination. However Iā€˜d like to keep the interface consistent between Mutex and Semaphore, and renaming the method on Mutex is not an option as it would break compatibility with existing code. The same issue exists with isLocked.

Besides, a semaphore is usually used to acquire exclusive access to one instance of a limited resource, so the naming might not be entirely bad on a second glance šŸ˜

from async-mutex.

Related Issues (20)

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.