new SemaphoresHash(name, resourcesNo, debug)
Constructor function. Creates a new SemaphoresHash with optional and resources number
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
name |
string |
<optional> |
"SemaphoresHash" | The name of the created SemaphoresHash |
resourcesNo |
number(integer) |
<optional> |
1 | The total numer of resources available |
debug |
boolean |
<optional> |
false | Defines if debugging messages should be shown during SemaphoresHash operations |
Example
// Example of two consumers var QPP = require('./..'); var s = new QPP.SemaphoresHash(); s.create('test1'); s.wait('test1'); s.wait('test2'); // semaphore 'test2' is implictly created when we try to listen for it (no need for explicit create) s.signal('test2'); s.signal('test1'); // For more examples, please check demo code and unit tests for @see qpp.SemaphoresHash
Members
-
#debug :boolean
-
defines if debugging messages should be shown during SemaphoresHash operations
Type:
- boolean
-
#semaphores :Array.<string, QPP.Semaphore>
-
array hash of semaphores
Type:
- Array.<string, QPP.Semaphore>
Methods
-
create()
-
create named semaphore in SemaphoresHash
Returns:
returns newly created semaphore
- Type
- QPP.Semaphore
-
signal()
-
release resources in the named of the SemaphoresHash
-
wait()
-
waits on SemaphoresHash
Returns:
promise that will get resolved after the named semaphore in the SemaphoresHash is available. The only possibility for promise to get rejected is when SemaphoresHash gets destroyed In that case it will get rejected with an @see
Error
.- Type
- external:Promise