diff options
| author | Emmanuel Gaillot <emmanuel.gaillot@gmail.com> | 2025-12-20 21:48:03 +0100 |
|---|---|---|
| committer | Emmanuel Gaillot <emmanuel.gaillot@gmail.com> | 2025-12-20 22:00:26 +0100 |
| commit | 37d26e407f903e87bbf4c247c8385b662319b620 (patch) | |
| tree | 6370d280ef411e0fdf26f853c4be8a2212093366 /lambda-calcul/javascript | |
| parent | 895e9a4fc2c1a427c55ebaafb5423d3db6e3dddc (diff) | |
| download | lambda-nantes-37d26e407f903e87bbf4c247c8385b662319b620.tar.gz | |
Wait for user input before ending
… In preparation for unregistering user at the end.
Diffstat (limited to 'lambda-calcul/javascript')
| -rw-r--r-- | lambda-calcul/javascript/index.js | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lambda-calcul/javascript/index.js b/lambda-calcul/javascript/index.js index a71697d..5c080d1 100644 --- a/lambda-calcul/javascript/index.js +++ b/lambda-calcul/javascript/index.js @@ -1,15 +1,37 @@ +const { createInterface } = require('readline/promises'); + const LC = require('./src/client'); const playerName = process.env.PLAYER_NAME || 'A shy user'; -client = LC.newClient({ +const client = LC.newClient({ playerName, challengerURL: process.env.CHALLENGER_URL, }); -client.start() - .then(token => console.log(`${playerName} has registered with token ${token}`) || token) - .then(client.nextChallenge) +let token; + +const solveNextChallenge = (token) => client + .nextChallenge(token) .then(challenge => console.log(`Next challenge: ${challenge}`) || challenge) .then(client.solve) .then(solution => console.log(`… solved into: ${solution}`)); + +const waitForEnterToBePressed = () => { + const readlineInterface = createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return readlineInterface.question('Done. Press Enter to finish.') + .then(() => readlineInterface.close()); +}; + +client.start() + .then(t => { + token = t; + console.log(`${playerName} has registered with token ${t}`); + }) + .then(() => solveNextChallenge(token)) + .then(() => waitForEnterToBePressed()) + .then(() => console.log('Done done!')); |
