getify/fasy

Feature: support async-generators (`async function*`)

开放

#3 创建于 2017年10月27日

 (6 条评论) (0 个反应) (0 位负责人)JavaScript (20 个派生)github user discovery
help wanted

仓库指标

星标
 (550 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Async-generators are stage3, so fairly likely to land in JS. Seems like fasy should support them eventually, probably sooner than later.

[UPDATE]: They landed in ES2018.

For example:

FP.serial.map(async function *mapper(v){
    if (await lookup(v)) v = yield something(v);
    return v;
});

Implementation should be fairly straightforward, in _runner(..).

Note: I don't think the for-await-of loop will work to run the async-generator, because that construct doesn't let us send a "next value" back in after each iteration. But I think we can do a for-of loop with await inside it, to get almost the same syntax-sugar but have the capability to drive the iterator as we need to. We'll look for Symbol.asyncIterator to know that we need to take this path.

However, before proceeding, we need to decide:

  • if the async-generator yields out a promise, do we wait on it and resume with its resolution, like we do in the normal generator-runner pattern?
  • if the async-generator has a final return value, is that indeed the overall completion value of that function's promise (in _runner(..))? Usually, returnd values from a generator would be thrown away
  • if the async-generator does not have a return value (or if it's return or return undefined), should we assume the last yielded value (or its resolution, if it was a promise) as the overall completion of that function's promise (in _runner(..))?

贡献者指南