gunsurvival / gunsurvival3

monorepo for gunsurvival 3
http://khoakomlem-internal.ddns.net:1810/
2 stars 0 forks source link

Thêm context cho mấy hàm server #4

Open khoakomlem opened 4 weeks ago

khoakomlem commented 4 weeks ago
const contexts = []

function retrieveContext() {
  return contexts[contexts.length-1]
}

async function a() {
  const index = contexts.push({amogus: true}) -1 
  b().then(e => console.log("b", e))
  contexts.splice(index, 1)
}

async function b() {
  return retrieveContext().amogus
}

async function c(context) { 
  return retrieveContext().amogus
}

a()
c().then(e => console.log("c", e))
// b should return true
// c should not be able to access the context

để ý javascript engine:

vì v8 có optimize JIT (just in time) nên code trên sẽ chạy (mặc dù trên lí thuyết async function return promise, which will be skipped to nextTick and not execute the retrieveContext before its removal)

image.png

linear[bot] commented 4 weeks ago

GUN-34 Thêm context cho mấy hàm server