Last active
May 2, 2019 09:29
-
-
Save wingyplus/e5c265c6d32b426bf4c868ba9e3ef08d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function cacheDo() { | |
return await cache.do(key, async () => { | |
return await db.findOne(); | |
}); | |
} | |
(async () => { | |
let missyou = await cacheDo(); | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
for let i = 0; i < datasets.length; i++ { | |
await dowith(datasets[i]); | |
} | |
})(); |
@llun ประมาณนั้นเลยครับ
ผมเข้าใจว่า mislead คือ โค้ดที่อ่านแล้วชวนให้เข้าใจผิด อารมณ์แบบ "คุณนึกว่า มันทำงานแบบนี้ใช่มั้ย จริงๆ แล้วมันทำงานแบบนี้ต่างหาก" ในกรณีของทั้งสองตัวอย่างข้างต้นผมเรียกมันว่า bad code ครับ คือ โปรแกรมมันทำงานอย่างที่โปรแกรมเมอร์อยากให้มันทำนั่นแหละ แต่มันไม่ใช่วิธีที่ดี และสิ่งที่วินพยายามจะสื่อสารคือ อย่าเขียนโค้ดแบบนี้ งี้ปะนะ
ผมติดอยู่อีกนิดเดียวคือ อยากรู้ว่า ต.ย. ที่หนึ่ง ถ้าเขียนให้ดีกว่านี้ จะเขียนยังไงนะครับ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mixth มันถูกในสิ่งที่ programmer อยากทำแต่ไม่ถูกใน js context เพราะธรรมชาติมันเป็น single thread เพราะฉะนั้นมันควรจะเป็นอะไรแนวๆ นี้
ท่านี้ทำ service ตายมานักต่อนักแล้ว T__T
ส่วน mislead.js นี่ชวนงงมาก หลายคนเข้าใจว่ามี async ต้องมี await ซึ่งจริงๆ แล้วมันไม่ต้องทำแบบนั้นก็ได้ พอเจอแบบนี้ก็มีคำถามอีกว่า await แบบนี้มันจะเกิดอะไรขึ้นเมื่อเทียบกับ return แบบไม่ใช้ await อีก