index.js
function(name, resourcesNo, waitForMoreDemandingConsumers, debug){
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} name - name of the semaphore
		*/
		this.name = name || "semaphore";
		resourcesNo = resourcesNo || 1;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} initialResources - initial (total) number of resources that semaphore has
		*/
		this.initialResources = resourcesNo;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} resourcesNo - currently available number of resources
		*/
		this.resourcesNo = resourcesNo;
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} waitingQueue - queue holding the list of waiting consumers (functions) for available resources
		*/
		this.waitingQueue = [];
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} waitForMoreDemandingConsumers=true - defines if consumer can allocate resources even if other consumer waits for available resources (but needs more resources than currently available)
		@example
		var s = new Semaphore('s', 3);
		var wP1 = s.wait(1); // fine, 2 resources left available
		var wP2 = s.wait(3); // not fine (consumer 1 has to release)
		// wP3 will be fine and resolved if {@link this.waitForMoreDemandingConsumers} === false
		// or not fine and not resolved until consumer 1's resources are released (signaled)
		// if {@link this.waitForMoreDemandingConsumers} === true (default)
		var wP3 = s.wait(2);
		*/
		this.waitForMoreDemandingConsumers = typeof waitForMoreDemandingConsumers !== 'undefined' ? waitForMoreDemandingConsumers : true;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} debug - defines if debugging messages should be shown during Semaphore operations
		*/
		this.debug = typeof debug !== 'undefined' ? debug : false;
	}
function(name, resourcesNo, waitForMoreDemandingConsumers, debug){
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} name - name of the semaphore
		*/
		this.name = name || "semaphore";
		resourcesNo = resourcesNo || 1;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} initialResources - initial (total) number of resources that semaphore has
		*/
		this.initialResources = resourcesNo;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} resourcesNo - currently available number of resources
		*/
		this.resourcesNo = resourcesNo;
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} waitingQueue - queue holding the list of waiting consumers (functions) for available resources
		*/
		this.waitingQueue = [];
		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} waitForMoreDemandingConsumers=true - defines if consumer can allocate resources even if other consumer waits for available resources (but needs more resources than currently available)
		@example
		var s = new Semaphore('s', 3);
		var wP1 = s.wait(1); // fine, 2 resources left available
		var wP2 = s.wait(3); // not fine (consumer 1 has to release)
		// wP3 will be fine and resolved if {@link this.waitForMoreDemandingConsumers} === false
		// or not fine and not resolved until consumer 1's resources are released (signaled)
		// if {@link this.waitForMoreDemandingConsumers} === true (default)
		var wP3 = s.wait(2);
		*/
		this.waitForMoreDemandingConsumers = typeof waitForMoreDemandingConsumers !== 'undefined' ? waitForMoreDemandingConsumers : true;

		/**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} debug - defines if debugging messages should be shown during Semaphore operations
		*/
		this.debug = typeof debug !== 'undefined' ? debug : false;
	}
function ( name , resourcesNo , waitForMoreDemandingConsumers , debug ) { /**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} name - name of the semaphore
		*/ this . name = name || "semaphore" ; resourcesNo = resourcesNo || 1 ; /**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} initialResources - initial (total) number of resources that semaphore has
		*/ this . initialResources = resourcesNo ; /**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {string} resourcesNo - currently available number of resources
		*/ this . resourcesNo = resourcesNo ; /**
		@memberof! qpp.SemaphoreMultiReservation#
		@private
		@var {string} waitingQueue - queue holding the list of waiting consumers (functions) for available resources
		*/ this . waitingQueue = [ ] ; /**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} waitForMoreDemandingConsumers=true - defines if consumer can allocate resources even if other consumer waits for available resources (but needs more resources than currently available)
		@example
		var s = new Semaphore('s', 3);
		var wP1 = s.wait(1); // fine, 2 resources left available
		var wP2 = s.wait(3); // not fine (consumer 1 has to release)
		// wP3 will be fine and resolved if {@link this.waitForMoreDemandingConsumers} === false
		// or not fine and not resolved until consumer 1's resources are released (signaled)
		// if {@link this.waitForMoreDemandingConsumers} === true (default)
		var wP3 = s.wait(2);
		*/ this . waitForMoreDemandingConsumers = typeof waitForMoreDemandingConsumers !== 'undefined' ? waitForMoreDemandingConsumers : true ; /**
		@memberof! qpp.SemaphoreMultiReservation#
		@var {boolean} debug - defines if debugging messages should be shown during Semaphore operations
		*/ this . debug = typeof debug !== 'undefined' ? debug : false ; }
Constructor function. Creates a new semaphore with optional name and resources number

@classdesc This is a class that provides promises enabled semaphores.
It differs from the class Semaphore (@see {@link qpp.Semaphore} ) in a way
it supports allocation of more than one resource in one wait() call

@example
Example of 3 groups
var QPP = require('qpp');
var s = new QPP.SemaphoreMultiReservation('Nebojsa tower', 5);

group 1
setTimeout(function(){
s.wait(3) // 3 people
.then(function(){ // resource is available, consuming resource
console.log("Group 1: Let's run to the top!");
setTimeout(function(){
console.log("Group 1: Great experience, but they ask us to leave!")
s.signal(3); // releasing resource (toilet)
}, parseInt(Math.random()*1500)+1);
});
}, parseInt(Math.random()*100)+1);

group 2
setTimeout(function(){
s.wait(4) // 4 people
.then(function(){ // resource is available, consuming resource
console.log("Group 2: Tower is available for us!");
setTimeout(function(){
console.log("Group 2: Let's give the space for others!")
s.signal(4); // releasing resource (toilet)
}, parseInt(Math.random()*500)+1);
});
}, parseInt(Math.random()*100)+1);

group 3
setTimeout(function(){
s.wait(2) // 2 people
.then(function(){ // resource is available, consuming resource
console.log("Group 3: Hey, i have to show you the view!");
setTimeout(function(){
console.log("Group 3: Ah, we could stay here forever!")
s.signal(2); // releasing resource (toilet)
}, parseInt(Math.random()*100)+1);
});
}, parseInt(Math.random()*100)+1);

This is the most interesting scenario:
Group 2: Tower is available for us
Group 2: Let's give the space for others
Group 3: Hey, i have to show you the view
Group 1: Let's run to the top
Group 3: Ah, we could stay here forever
Group 1: Great experience, but they ask us to leave!
Because both group 1 and 3 ended up at the top of the towe simultaneously
(there were enough of resources to allocate for both (2+3<=5))

For more examples, please check unit tests for @see qpp.mapBandwidth

@memberof qpp
@exports qpp.Semaphore
@class qpp.SemaphoreMultiReservation
@param {string} [name="semaphore"] - The name of the created semaphore
@param {number(integer)} [resourcesNo=1] - The total numer of resources available
@param {boolean} [debug=false] - Defines if debugging messages should be shown during Semaphore operations
@param {boolean} [waitForMoreDemandingConsumers=true] - Defines if consumer can allocate resources even if other consumer waits for available resources (but needs more resources than currently available)
@param {boolean} [debug=false] - Defines if debugging messages should be shown during Semaphore operations
Constructor function . Creates a new semaphore with optional name and resources number