Baseline Widely available
AsyncGenerator
ê°ì²´ë async generator functionì ìí´ ë°íëë©°, ë¹ë기 ìí íë¡í ì½ê³¼ ë¹ë기 ë°ë³µì íë¡í ì½ì 모ë ì¤ìí©ëë¤.
ë¹ë기 ìì±ê¸° ë©ìëë íì Promise
ê°ì²´ë¥¼ ì°ì¶í©ëë¤.
AsyncGenerator
ë ì¨ê²¨ì§ AsyncIterator
í´ëì¤ì íì í´ëì¤ì
ëë¤.
async function* foo() {
yield await Promise.resolve("a");
yield await Promise.resolve("b");
yield await Promise.resolve("c");
}
let str = "";
async function generate() {
for await (const val of foo()) {
str = str + val;
}
console.log(str);
}
generate();
// Expected output: "abc"
ìì±ì
AsyncGenerator
ìì±ìì ëìëë JavaScript ê°ì²´ë ììµëë¤. ë¹ë기 ìì±ê¸° í¨ììì AsyncGenerator
ì ì¸ì¤í´ì¤ë¥¼ ë°íí´ì¼ í©ëë¤.
async function* createAsyncGenerator() {
yield await Promise.resolve(1);
yield await Promise.resolve(2);
yield await Promise.resolve(3);
}
const asyncGen = createAsyncGenerator();
asyncGen.next().then((res) => console.log(res.value)); // 1
asyncGen.next().then((res) => console.log(res.value)); // 2
asyncGen.next().then((res) => console.log(res.value)); // 3
ë¹ë기 ìì±ê¸° í¨ìê° ìì±í, 모ë ê°ì²´ê° ê³µì íë íë¡í íì
ê°ì²´ì¸ ì¨ê²¨ì§ ê°ì²´ë§ ììµëë¤. ì´ ê°ì²´ë í´ëì¤ì²ë¼ ë³´ì´ê² í기 ìí´ ì¢
ì¢
AsyncGenerator.prototype
ì¼ë¡ ê·¸ë ¤ì§ì§ë§, AsyncGeneratorFunction
ì ì¤ì JavaScript ê°ì²´ì´ê¸° ë문ì AsyncGeneratorFunction.prototype.prototype
ë¼ê³ íë ê²ì´ ë ì ì í©ëë¤. AsyncGenerator
ì¸ì¤í´ì¤ì íë¡í íì
ì²´ì¸ì ì´í´íë ¤ë©´ AsyncGeneratorFunction.prototype.prototype
를 참조íì¸ì.
ìë ìì±ì AsyncGenerator.prototype
ì ì ìëì´ ìì¼ë©° 모ë AsyncGenerator
ì¸ì¤í´ì¤ìì ê³µì ë©ëë¤.
AsyncGenerator.prototype.constructor
ì¸ì¤í´ì¤ ê°ì²´ë¥¼ ìì±íë ìì±ì í¨ìì
ëë¤. AsyncGenerator
ê°ì²´ë¥¼ ìí ì´ê¸° ê°ì AsyncGeneratorFunction.prototype
ì
ëë¤.
ì°¸ê³ :
AsyncGenerator
ê°ì²´ë ìì ì ìì±í ë¹ë기 ìì±ê¸° í¨ìì 참조를 ì ì¥íê³ ìì§ ììµëë¤.
AsyncGenerator.prototype[@@toStringTag]
@@toStringTag
ìì±ì ì´ê¸° ê°ì 문ìì´ "AsyncGenerator"
ì
ëë¤. ì´ ìì±ì Object.prototype.toString()
ìì ì¬ì©í©ëë¤.
ë¶ëª¨ AsyncIterator
ìì ì¸ì¤í´ì¤ ë©ìë를 ììí©ëë¤.
AsyncGenerator.prototype.next()
Promise
를 ë°ííë©°, yield
ííìì ìí´ ì°ì¶ëì´ ì£¼ì´ì§ ê°ì¼ë¡ ì´íë©ëë¤.
AsyncGenerator.prototype.return()
íì¬ ì¼ì ì¤ë¨ë ìì¹ìì ìì±ê¸° 본문ì return
ë¬¸ì´ ì½ì
ëì´ ìì±ê¸°ë¥¼ ì¢
ë£íê³ try...finally
ë¸ë¡ê³¼ ê²°í©íì¬ ì 리 ìì
ì ìíí ì ìë ê²ì²ë¼ ìëí©ëë¤.
AsyncGenerator.prototype.throw()
íì¬ ì¼ì ì¤ë¨ë ìì¹ì ìì±ê¸° 본문ì throw
문ì ì½ì
íì¬ ìì±ê¸°ì ì¤ë¥ ìí를 ìë¦¬ê³ ì¤ë¥ë¥¼ ì²ë¦¬íê±°ë ì 리를 ìííê³ ì¤ì¤ë¡ ë«ì ì ìëë¡ íë ê²ì²ë¼ ìëí©ëë¤.
ìëë ë¹ë기 ìì±ê¸°ë¥¼ ìííë ìì ì
ëë¤. 1~6ì ê°ì ì ì ì¤ì´ëë ìê° ê°ê²©ì¼ë¡ ì½ìì ë¨ê¹ëë¤. íë¡ë¯¸ì¤ê° ì°ì¶ë ëë§ë¤ for await...of
루í ë´ìì ìëì¼ë¡ ì´íëë ê²ì íì¸í ì ììµëë¤.
// ë¹ë기 ìì
ì
ëë¤. ì¤ì ë¡ ë ì ì©í ì¼ì íê³ ìë¤ê³ ê°ì í´ ë³´ì기 ë°ëëë¤.
function delayedValue(time, value) {
return new Promise((resolve /*, reject*/) => {
setTimeout(() => resolve(value), time);
});
}
async function* generate() {
yield delayedValue(2000, 1);
yield delayedValue(100, 2);
yield delayedValue(500, 3);
yield delayedValue(250, 4);
yield delayedValue(125, 5);
yield delayedValue(50, 6);
console.log("All done!");
}
async function main() {
for await (const value of generate()) {
console.log("value", value);
}
}
main().catch((e) => console.error(e));
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4