kihlh / hmn-win32

hmc-win32的子集 仅处理网络部分
https://kihlh.gitbook.io/hmc/
MIT License
1 stars 0 forks source link

getTCPv4PortProcessIDAsync Promise error #2

Closed xianyunleo closed 2 months ago

xianyunleo commented 3 months ago
  const net = require('net-win32')
  const arr = [9005, 3306]
  await Promise.all(arr.map(async port => {
    return await net.getTCPv4PortProcessIDAsync(port)
  }))

throw error : PromiseGetPortProcessID::startWork work_message -> error < Promise workspace has not been released. >

kihlh commented 3 months ago

请勿并发

xianyunleo commented 3 months ago

Promise.all 在代码里很常见的,就算不写 Promise.all。用一个async方法包裹后,调用此async方法,前面不加await,也同样会报这个错误 @kihlh

xianyunleo commented 3 months ago
const arr = [9005, 3306]
const asyncFunc = async(port)=>{
    const pid = await net.getTCPv4PortProcessIDAsync(port)
    if (pid) await ProcessExtend.kill(pid)
}

for (const port of arr) {
    asyncFunc(port)
}

比如以上的代码,调用 asyncFunc前不加await,也会触发promise的错误 @kihlh

kihlh commented 2 months ago

net-win32@1.0.2 中已经修复