1.0.1 • Published 3 years ago

nv-facutil-while v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

nv-facutil-while

  • nv-facutil-while is a simple-util to avoid using-of-while
  • support async conder AND async handler

install

  • npm install nv-facutil-while

usage

 const { simple_while,simple_while_cache } = require("nv-facutil-while");

example

simple

    var ctx = {i:0}

    async function conder(ctx) {return(ctx.i<5)}

    async function handler(ctx) {
        let p = new Promise(
            (rs,rj)=> {
                setTimeout(()=>{
                    console.log(new Date);
                    rs([new Date,ctx.i]);
                },3000);
            }
        );
        return(p)
    }

    async function stepper(ctx) {ctx.i = ctx.i +1;}


    > ctx
    { i: 0 }
    >
    > await simple_while(ctx,conder,handler,stepper);
    2021-09-14T09:21:04.961Z
    2021-09-14T09:21:07.968Z
    2021-09-14T09:21:10.973Z
    2021-09-14T09:21:13.978Z
    2021-09-14T09:21:16.982Z
    [ 2021-09-14T09:21:16.983Z, 4 ]
    >
    > ctx
    { i: 5 }
    >

APIS

  • simple_while(ctx,conder,handler,stepper)
  • simple_while_cache(ctx,conder,handler,stepper,cache_key='___cahce___')

LICENSE

  • ISC