Class: SemaphoresHash

SemaphoresHash

This is a class that provides promises enabled SemaphoresHashes. It is possible to create a SemaphoresHash with a name and speciffic number of resources that we can wait for to get available, and release them when we do not need them anymore


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

Source:
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
Source:

#semaphores :Array.<string, QPP.Semaphore>

array hash of semaphores

Type:
  • Array.<string, QPP.Semaphore>
Source:

Methods


create()

create named semaphore in SemaphoresHash

Source:
Returns:

returns newly created semaphore

Type
QPP.Semaphore

signal()

release resources in the named of the SemaphoresHash

Source:

wait()

waits on SemaphoresHash

Source:
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