Created
December 12, 2017 14:04
-
-
Save jooyunghan/1b20d8b605b7b3a1d26dd16c83adb6c0 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
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