Giter Site home page Giter Site logo

Comments (3)

DirtyHairy avatar DirtyHairy commented on June 9, 2024 1

Thanks for the pointer to the console, hiding in plain sight. I can observe the same phenomenon in the log as you, so it superficially looks like the lock is not taking effect, but look what happens after adding a timestamp to the log:

image

(the timestamp is the second number, the first one is an instance ID that I added to the mutex in order to make sure that this is not some weird effect of hot reloading). Both logs a separated by ~2000 msec, as expected. This is just an output issue, it seems that the console sometimes misses updates.

from async-mutex.

DirtyHairy avatar DirtyHairy commented on June 9, 2024

HI @trajano !

Sorry, I don't seem to be able to access the console in the virtual devices linked in the snack. However, I see two problems with your code:

  1. You create a new instance of the mutex each time the component renders. Thus, a rerender between calls to your handlers will create a new mutex, and the async code in the handlers can interleave. You should either wrap the mutex in useRef or use a module-global instance.
  2. You execute await mutex.lock() before your call to mutex.runExclusive() and never release the lock. This means that the mutex stays locked, and the code wrapped in runExclusive never executes. This consistent with your log messages, which seem to originate from startMutexTxn() (and not startMutexTxn2).

from async-mutex.

trajano avatar trajano commented on June 9, 2024

Thanks let me fix it I think it was a left over copy and paste. Though it was an await mutex.acquire() not lock() I'll revert it back to use a useRef to prevent the re-renders. Mind you with the supposed rerenders it also works (not I don't think the code rerenders anyway because I write the output to the logs).

Logs are here
image
then
image

However, like I said it's hard to replicate. Anyway closing this for now but we can probably re-open in case someone else has an issue at least the snack is there to help replicate the issue.

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.