Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created December 12, 2017 14:04
Show Gist options
  • Save jooyunghan/1b20d8b605b7b3a1d26dd16c83adb6c0 to your computer and use it in GitHub Desktop.
Save jooyunghan/1b20d8b605b7b3a1d26dd16c83adb6c0 to your computer and use it in GitHub Desktop.
function* knockCodeHandler(preset) {
while (true) {
const input = [];
// after read first input
input.push(getCode(yield));
// keep reading input with timeout(1s)
while (true) {
const e = yield timeout(1000);
if (e) {
input.push(getCode(e));
} else {
break;
}
}
if (input.join('') === preset) {
success();
} else {
failure(input.join(''));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment