mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 22:14:22 +00:00
fix(cliproxy): prevent race in promptNickname close handler
This commit is contained in:
1 parent
5970e70e26
commit
107e2813f9
1 file changed
+10
-2
@@ -76,8 +76,15 @@ async function promptNickname(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<string | null>((resolve) => {
|
return new Promise<string | null>((resolve) => {
|
||||||
// Handle Ctrl+C gracefully
|
let resolved = false;
|
||||||
rl.on('close', () => resolve(null));
|
|
||||||
|
// Handle Ctrl+C gracefully (only if not already resolved)
|
||||||
|
rl.on('close', () => {
|
||||||
|
if (!resolved) {
|
||||||
|
resolved = true;
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const askForNickname = () => {
|
const askForNickname = () => {
|
||||||
rl.question('[?] Enter a nickname for this account: ', (answer) => {
|
rl.question('[?] Enter a nickname for this account: ', (answer) => {
|
||||||
@@ -102,6 +109,7 @@ async function promptNickname(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolved = true;
|
||||||
rl.close();
|
rl.close();
|
||||||
resolve(nickname);
|
resolve(nickname);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user