Skip to content

Commit

Permalink
Merge pull request #1 from codevor/refactor/interval-usage
Browse files Browse the repository at this point in the history
Refactor(semaphore): setInterval to setTimeout
  • Loading branch information
caian-gums authored Nov 29, 2019
2 parents accc448 + bda0337 commit 42f84b3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/semaphore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ const Semaphore = ({ resources = 1, start = resources } = {}) => {
}

return new Promise(resolve => {
setTimeout(() => {
acquire().then(() => {
const acquireInterval = setInterval(() => {
if (counter > 0) {
counter -= 1;
clearInterval(acquireInterval);

resolve();
});
}
}, timespan() * 1000);
});
};
Expand Down

0 comments on commit 42f84b3

Please sign in to comment.