Last active
December 15, 2015 16:38
-
-
Save you21979/5290136 to your computer and use it in GitHub Desktop.
指定した時間で回数制限を行う関数。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createLimitter = function(max, reset_sec){ | |
var reset_time = process.uptime() + reset_sec; | |
var count = 0; | |
return function(){ | |
if(process.uptime() >= reset_time){ | |
reset_time = process.uptime() + reset_sec; | |
count = 0; | |
} | |
if(count >= max){ | |
return false; | |
} | |
count++; | |
return true; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment