tangmou's recent timeline updates
tangmou

tangmou

V2EX member #351541, joined on 2018-09-22 21:00:37 +08:00
tangmou's recent replies
@likooo125802023 #52 steam 支持还不错的
@remrin https://chenjianyong.com/ 我就是用的这个主题, 小改了一下
又来了, 阿里造神运动...
May 26, 2024
Replied to a topic by houhaibushihai Python 《流畅的 Python 》 英文版有 2 本书?
@cloudyplain +1, 买了中文版然而被翻译和纸的质量劝退...
Jan 6, 2024
Replied to a topic by icoming JavaScript 为什么 Promise 会有这种表现?
@tangmou #16 为啥我的 markdown 没有渲染出来...
Jan 6, 2024
Replied to a topic by icoming JavaScript 为什么 Promise 会有这种表现?
@lisxour #5
@tangmou 代码忘了贴了:

```javascriipt
// 需要订购的产品链接
const productList = [
"https://xxx",
"https://xxx",
"https://xxx"
]

async function asyncSleep(duration) {
await new Promise(r => setTimeout(r, duration));
}

// 是否有货
async function hasStock(url) {
await asyncSleep(2000);
return false
}

// 开始订购
const startOrder = async () => {
const promises = productList.map(u => ({tag: u, promise: hasStock(u)}))
const results = await Promise.allSettled(promises)
for (const [i, result] of results.entries()) {
// 是否有货,有就订购
if (!result.value) {
console.log("无货", promises[i].tag)
continue
}
}
}

function exitHandler(options, exitCode) {
console.log("process exit:", performance.now());
}

process.on('exit', exitHandler.bind(null,{cleanup:true}));

console.log("before:", performance.now());
startOrder();
console.log("after:", performance.now());
```
Jan 6, 2024
Replied to a topic by icoming JavaScript 为什么 Promise 会有这种表现?
@lisxour #5 即使 hasStock 里面进行了 `await` 也不影响, 因为对于 `hasStock` 本身没有进行 `await`; 这里 `startOrder` 这个函数不会卡顿 (使用 "错误的处理"), 可能的一个原因是, 通过 node.js 处理时, 它会把所有 pending 的 promise 都处理完, 所以是卡在其他地方了. 比如下面这个代码:

```javascript
```
Sep 11, 2023
Replied to a topic by iorilu 程序员 有多少人完全使用命令行管理 git 得
很舒服的文字, 感谢 OP !

看完之后我的感受和 OP 对象一样: "这些英国人知道他们这种习以为常的生活是一种特权吗".
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3039 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 19ms · UTC 13:34 · PVG 21:34 · LAX 06:34 · JFK 09:34
♥ Do have faith in what you're doing.