Skip to content

Instantly share code, notes, and snippets.

@imyelo
Created July 8, 2014 10:59
Show Gist options
  • Save imyelo/459be0c7d255eb616518 to your computer and use it in GitHub Desktop.
Save imyelo/459be0c7d255eb616518 to your computer and use it in GitHub Desktop.
lockable.js
var lockable = function (func) {
var isLocking = false;
var unlock = function () {
isLocking = false;
};
return function () {
var args = arguments;
if (isLocking) {
return;
}
isLocking = true;
func.apply(this, [unlock].concat(Array.prototype.slice.call(args, 0)));
};
};
var a = lockable(function (unlock, b) {
setTimeout(unlock, 1000);
console.log(b);
});
a('123');
a('asdf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment