index.js
/**
 * Allows you to 'call' a function multiple times, each time with a callback supplied, but only ever have one instance of the function running concurrently
 * 
 * @param  {Function} func - An anonymous function with a single callback param, which -inside- calls your real function. Example: function (roCallback) { myRealFunction(roCallback); }
 * @param  {Function} callback - Callback to call
 */
Allows you to 'call' a function multiple times, each time with a callback supplied, but only ever have one instance of the function running concurrently

@param  {Function} func - An anonymous function with a single callback param, which -inside- calls your real function. Example: function (roCallback) { myRealFunction(roCallback); }
@param  {Function} callback - Callback to call
Allows you to ' call ' a function multiple times each time with a callback supplied but only ever have one instance of the function running concurrently @param { Function } func - An anonymous function with a single callback param which - inside - calls your real function . Example : function ( roCallback ) { myRealFunction ( roCallback ) ; } @param { Function } callback - Callback to call
function oneConcurrent(func, callback) {
	let funcName = func; 
	var getStoredCallbacks = function () {
		oneConcurrent.callbacks = oneConcurrent.callbacks || {}; 
		oneConcurrent.callbacks[funcName] = oneConcurrent.callbacks[funcName] || []; 
		return oneConcurrent.callbacks[funcName];
	};
	var removeStoredCallbacks = function () {
		delete oneConcurrent.callbacks[funcName];
	};
	var callbacks = getStoredCallbacks();
	callbacks.push(callback); 
	if (callbacks.length == 1) { 
		var fauxCallback = function () { 
			for (var i in callbacks) {
				let callback = callbacks[i];
				callback.apply(this, arguments); 
			}
			removeStoredCallbacks(); 
		};
		func(fauxCallback); 
	}
}
function oneConcurrent ( func , callback ) { let funcName = func ; var getStoredCallbacks = function ( ) { oneConcurrent . callbacks = oneConcurrent . callbacks || { } ; oneConcurrent . callbacks [ funcName ] = oneConcurrent . callbacks [ funcName ] || [ ] ; return oneConcurrent . callbacks [ funcName ] ; } ; var removeStoredCallbacks = function ( ) { delete oneConcurrent . callbacks [ funcName ] ; } ; var callbacks = getStoredCallbacks ( ) ; callbacks . push ( callback ) ; if ( callbacks . length == 1 ) { var fauxCallback = function ( ) { for ( var i in callbacks ) { let callback = callbacks [ i ] ; callback . apply ( this , arguments ) ; } removeStoredCallbacks ( ) ; } ; func ( fauxCallback ) ; } }
Allows you to 'call' a function multiple times, each time with a callback supplied, but only ever have one instance of the function running concurrently
Allows you to ' call ' a function multiple times each time with a callback supplied but only ever have one instance of the function running concurrently
// func.name returned nothing, so using the Function object itself as a key // Ensure there's a persistant key=>value object to store callbacks // Ensure there's an array, with the function as the key, in our callbacks object // Add the supplied callback // Only actually run the supplied function if there is just one callback already stored; i.e. if it's the first run // This faux callback will let us eventually call all of the stored callbacks // Call this stored callback, with any/all arguments that were provided // Remove our stored callbacks // Call the supplied function, supplying it with a single faux callback