My use case is similar to what Dean has showed:
My `run()` lib abstraction should work with:
* a function, with node's done() callback style
* a generator function, with co's yield promise style [1]
```
// ES5 function
run(function (data, done) {
doSomeAsyncJob(data, done)
})
// Generator function
run(function* (data) {
return yield getSomeAsyncJobPromise(data)
})
```
[1] https://www.npmjs.com/package/co
On Tue, Mar 3, 2015 at 5:54 PM, Dean Landolt <[email protected]> wrote:
> One use case is for coroutine runners which accept either generators or
> generator functions:
>
> https://github.com/deanlandolt/copromise/blob/master/copromise.js#L34-L36
>
> Is there a better way to accomplish this?
>
>
> On Tue, Mar 3, 2015 at 12:12 PM, Erik Arvidsson <[email protected]>
> wrote:
>
>> Why do you want to do this?
>>
>> It is an antipattern that we have covered before.
>>
>> On Tue, Mar 3, 2015 at 5:41 PM Guilherme Souza <[email protected]> wrote:
>>
>>> Hi all,
>>>
>>> I was wondering how one could check if a given function is a generator
>>> function, is a cross-realm way:
>>>
>>> ```
>>> let f = function(){}
>>> let g = function*(){}
>>>
>>> typeof f === typeof g // 'function'
>>>
>>> f instanceof Function // true, but only in the same Realm
>>> g instanceof Function // true, but again only in the same Realm
>>>
>>> let GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor
>>> f instanceof GeneratorFunction // false
>>> g instanceof GeneratorFunction // true, but only in the same Realm
>>>
>>> // This works, but relies on Function.prototype being a function itself.
>>> typeof Object.getPrototypeOf(f) // 'function'
>>> typeof Object.getPrototypeOf(g) // 'object'
>>> ```
>>>
>>> So what is the recommended way to do this type of check?
>>> Would something like `Array.isArray` for generator functions be helpful?
>>>
>>> Regards,
>>> Gui
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
--
Graduando em Engenharia de Controle e Automação
*Universidade Estadual de Campinas*
http://sitegui.com.br
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss