重构 async

This commit is contained in:
ExplodingDragon
2025-11-20 12:42:05 +08:00
parent d6440ebb02
commit dedcd58f8e
6 changed files with 73 additions and 55 deletions

View File

@@ -1,18 +1,21 @@
let ws = websocket();
let shouldExit = false;
while (!shouldExit) {
let data = ws.readText();
switch (data) {
case "exit":
shouldExit = true;
break;
case "panic":
throw Error("错误");
case "date":
ws.writeText(new Date().toJSON())
break
default:
ws.writeText("收到信息:" + data)
break;
async function run() {
let ws = websocket();
let shouldExit = false;
while (!shouldExit) {
let data = await ws.readText();
switch (data) {
case "exit":
shouldExit = true;
break;
case "panic":
throw Error("错误");
case "date":
ws.writeText(new Date().toJSON())
break
default:
ws.writeText("收到信息:" + data)
break;
}
}
}
}
run().then(r => {});