Skip to content

Instantly share code, notes, and snippets.

@brigand

brigand/.js Secret

Created August 18, 2018 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/e21a16edaad24673bbeef810ed346634 to your computer and use it in GitHub Desktop.
Save brigand/e21a16edaad24673bbeef810ed346634 to your computer and use it in GitHub Desktop.
const manager = {
counter: 1,
user: null,
pass: null,
receiveCreds(user, pass) {
manager.user = user;
manager.pass = pass;
// increment counter
manager.counter += 1;
// store a SNAPSHOT of the counter, which
// can be used inside the closures
const counter = manager.counter;
setTimeout(() => {
if (cred.counter !== counter) {
// receiveCreds has been called again,
// which caused the counter to increment
return;
}
clearCredentials();
}, ONE_HOUR);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment