All files / src AsyncParallelResultAllHook.ts

90.91% Statements 30/33
62.5% Branches 5/8
100% Functions 12/12
90.32% Lines 28/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 722x 2x       6x 6x 6x       4x       2x       6x 6x       6x 11x   10x     11x       11x   11x     11x 11x 11x 11x     6x       6x       2x         7x 7x       6x 6x   6x       2x  
import CodeFactory from './CodeFactory'
import Hook from './Hook'
 
class AsyncParallelResultAllHookCodeFactory extends CodeFactory {
    header() {
        let code = super.header()
        code += 'var asyncParallelResMap = {};\n'
        return code
    }
 
    createContentPromiseDone() {
        return () => '_resolve(asyncParallelResMap);\n'
    }
 
    createContentAsyncDone(): () => string {
        return () => '_callback(null, asyncParallelResMap);\n'
    }
 
    content({ onError, onResult, onDone }: CodeFactoryContent) {
        let code = ''
        Iif (!this.options || !onResult) {
            return code
        }
 
        code += this.callTapsParallel({
            onError: (_i, err, _done, doneBreak) => onError(err) + doneBreak(true),
            onTap: (_i, run) => {
                return run()
            },
            onResult: (i, result, done) => {
                Iif (!this.options) {
                    return undefined
                }
 
                const tap = this.options.taps[i]
 
                Iif (!tap.name) {
                    return undefined
                }
                let _code = ''
                _code += `asyncParallelResMap["${tap.name}"] = ${result}\n`
                _code += done()
                return _code
            },
            onDone: () => {
                return onDone()
            }
        })
 
        return code
    }
}
 
const codeFactory = new AsyncParallelResultAllHookCodeFactory()
 
class AsyncParallelResultAllHook extends Hook {
    private fns: any[] | undefined
    constructor(args: string[], name?: string) {
        super(args, name)
        this.forbiddenCall()
    }
 
    compile(options: HookCompileOptions) {
        this.fns = []
        codeFactory.setup(this.fns, options)
 
        return codeFactory.create(options)
    }
}
 
export default AsyncParallelResultAllHook