exposed AsyncFunction constructor in Function.js...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-07-07 11:39:08 +03:00
parent 95504c27c5
commit cc9824c9a9
5 changed files with 54 additions and 4 deletions

View File

@ -212,9 +212,12 @@ object.Mixin('ArrayMixin', 'soft', {
// done...
: [] },
// XXX add handler function support -- a-la generator.js'
iter: function*(lst=[]){
yield* lst.iter() },
// XXX not sure about the handler API here yet...
iter: function*(lst=[], handler=undefined){
yield* lst.iter(
...(handler ?
[handler]
: [])) },
})

18
Function.js Normal file
View File

@ -0,0 +1,18 @@
/**********************************************************************
*
*
*
**********************************************/ /* c8 ignore next 2 */
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
var AsyncFunction =
module.AsyncFunction =
(async function(){}).constructor
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })

View File

@ -13,6 +13,8 @@ Library of JavaScript type extensions, types and utilities.
- [`Object.matchPartial(..)`](#objectmatchpartial)
- [`<object>.run(..)`](#objectrun)
- [`Object.sort(..)`](#objectsort)
- [`Function`](#function)
- [`func.AsyncFunction`](#funcasyncfunction)
- [`Array`](#array)
- [`<array>.first(..)` / `<array>.last(..)`](#arrayfirst--arraylast)
- [`<array>.rol(..)`](#arrayrol)
@ -454,6 +456,30 @@ Object.keys(Object.sort(o, ['x', 'a', '100']))
This is similar to [`<map>.sort(..)`](#mapsort) and [`<ser>.sort(..)`](#setsort).
## `Function`
```javascript
var func = require('ig-types/Function')
```
### `func.AsyncFunction`
The async function constructor.
This enables us to test if an object is an instance of an async function.
```javascript
var a = async function(){
// ...
}
a instanceof func.AsyncFunction // -> true
```
This is hidden by JavaScript by default.
## `Array`
```javascript

View File

@ -22,6 +22,7 @@ module.patchDate = require('./Date').patchDate
// Additional types...
module.containers = require('./containers')
module.func = require('./Function')
module.generator = require('./generator')
module.event = require('./event')
module.runner = require('./runner')
@ -31,7 +32,9 @@ module.runner = require('./runner')
module.STOP = object.STOP
// frequently used stuff...
module.AsyncFunction = module.func.AsyncFunction
module.Generator = module.generator.Generator
module.AsyncGenerator = module.generator.AsyncGenerator
// XXX doc...
module.iter = module.generator.iter

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "6.15.6",
"version": "6.15.7",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {