How to implement a lock in JavaScript

前端 未结 8 951
青春惊慌失措
青春惊慌失措 2020-12-04 07:49

How could something equivalent to lock in C# be implemented in JavaScript?

So, to explain what I\'m thinking a simple use case is:

User clicks

8条回答
  •  悲哀的现实
    2020-12-04 08:21

    I've had success mutex-promise.

    I agree with other answers that you might not need locking in your case. But it's not true that one never needs locking in Javascript. You need mutual exclusivity when accessing external resources that do not handle concurrency.

提交回复
热议问题