You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This proposal subsumes Luca's [Semaphore proposal](https://github.com/lucacasonato/proposal-semaphore).
89
89
90
-
Semaphore is a [counting semaphore](https://en.wikipedia.org/wiki/Semaphore_%28programming%29) that implements the Governor interface and extends Governor. It can be given a non-negative integral Number *capacity* and it is responsible for ensuring that there are no more than that number of active GovernorTokens simultaneously.
90
+
CountingGovernor is a [counting semaphore](https://en.wikipedia.org/wiki/Semaphore_%28programming%29) that implements the Governor interface and extends Governor. It can be given a non-negative integral Number *capacity* and it is responsible for ensuring that there are no more than that number of active GovernorTokens simultaneously.
91
91
92
92
#### Open Questions
93
93
94
94
- are idle listeners useful?
95
-
- triggered whenever the Semaphore hits "full" capacity (0 active GovernorTokens)
95
+
- triggered whenever the CountingGovernor hits "full" capacity (0 active GovernorTokens)
96
96
-`addIdleListener(cb: () => void): void`
97
97
-`removeIdleListener(cb: () => void): void`
98
98
- callback interface or EventTarget?
99
-
- are there concerns about sharing Semaphores across Agents?
99
+
- are there concerns about sharing CountingGovernors across Agents?
100
100
- alternative name: CountingGovernor? CountingRegulator?
101
101
102
102
### AsyncIterator.prototype integration
@@ -114,7 +114,7 @@ When not passed, these methods operate serially, as they do in the async iterato
114
114
115
115
This proposal also adds a `limit(governor)` method (the dual of `governor.wrapIterator(iterator)`) that returns a concurrency-limited AsyncIterator.
116
116
117
-
Because Semaphore will be an extremely commonly-used Governor, anywhere a Governor is accepted in any AsyncIterator.prototype method, a non-negative integral Number may be passed instead. It will be treated as if a Semaphore with that capacity was passed. Because of this, we are able to widen the first parameter of the `buffered` helper to accept a Governor in addition to the non-negative integral Number that it accepts as part of the async iterator helpers proposal.
117
+
Because CountingGovernor will be an extremely commonly-used Governor, anywhere a Governor is accepted in any AsyncIterator.prototype method, a non-negative integral Number may be passed instead. It will be treated as if a CountingGovernor with that capacity was passed. Because of this, we are able to widen the first parameter of the `buffered` helper to accept a Governor in addition to the non-negative integral Number that it accepts as part of the async iterator helpers proposal.
118
118
119
119
#### Open Questions
120
120
@@ -134,8 +134,8 @@ Because Semaphore will be an extremely commonly-used Governor, anywhere a Govern
@@ -149,12 +149,12 @@ Because Semaphore will be an extremely commonly-used Governor, anywhere a Govern
149
149
150
150
### Why the generic Governor interface?
151
151
152
-
While a semaphore is a common concurrency control mechanism, there are many other ways to control concurrency. Some examples of these:
152
+
While a counting semaphore is a common concurrency control mechanism, there are many other ways to control concurrency. Some examples of these:
153
153
154
154
- A governor that allows for a burst of activity before enforcing a limit (e.g. a semaphore that allows for 10 concurrent operations, but allows for 20 concurrent operations for the first 5 seconds).
155
155
- A distributed governor that enforces a concurrency limit across multiple machines using a distributed lock or consensus algorithm.
156
156
- A governor that enforces a concurrency limit based on the current load of the system (e.g. a semaphore that allows for 10 concurrent operations, but allows for 20 concurrent operations if the system is under 50% load).
157
157
158
158
Because of this variety of use cases, it is important to give developers the flexibility to use their own concurrency control mechanisms with built in JavaScript APIs.
159
159
160
-
The `Semaphore` class provides a simple and common concurrency control mechanism that can be used in many cases. It is expected that many developers will use `Semaphore` for their concurrency control needs. However, because APIs don't explicitly take a `Semaphore` instance, but any object that implements the `Governor` interface, developers can use their own concurrency control mechanisms if they need to.
160
+
The `CountingGovernor` class provides a simple and common concurrency control mechanism that can be used in many cases. It is expected that many developers will use `CountingGovernor` for their concurrency control needs. However, because APIs don't explicitly take a `CountingGovernor` instance, but any object that implements the `Governor` interface, developers can use their own concurrency control mechanisms if they need to.
0 commit comments