1.0.2 • Published 2 years ago

nv-facutil-idlock v1.0.2

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

nv-facutil-idlock

  • simple promise sema

install

  • npm install nv-facutil-idlock

usage

   const {creat} = require("nv-facutil-idlock");      

example

        const pool = creat("idpool")

        /*
        > pool
        Pool [idpool] {}
        >
        */


         var lock0 = pool.acquire("abcdefg")
        /*
        > lock0
        true

        > pool.abcdefg.used_
        1
        > pool.abcdefg.pending_
        0
        >

        */


        var lock1 = pool.acquire("abcdefg")

        /*
        > lock1
        Promise {
          <pending>,
          [Symbol(async_id_symbol)]: 282,
          [Symbol(trigger_async_id_symbol)]: 5,
          [Symbol(destroyed)]: { destroyed: false }
        }

        > pool
        Pool [idpool] { abcdefg: Lock {} }
        >

        > pool.abcdefg.used_
        1
        > pool.abcdefg.pending_
        1
        >

        */


        pool.release("abcdefg")

        /*
        > pool
        Pool [idpool] { abcdefg: Lock {} }
        > pool.abcdefg.used_
        1
        > pool.abcdefg.pending_
        0
        >
        */

        pool.release("abcdefg")

        /*
        >
        true
        > pool
        Pool [idpool] {}
        >
        */

METHODS

Pool

 pool.acquire(id)                          
 pool.release(id)

 ////
 pool.aexec(id, ahandle:async ()=>{},rollback:async ()=>{})
 ////

 pool.ids_                 
 pool.size_
 pool.total_pending_      
 pool.total_used_

 pool.exist(id)

Lock

lock.id_;
lock.pool_;

lock.can_disconn();
lock._disconn();
lock.disconn();

lock'super.acquire()  
lock'super.release()

APIS

LICENSE

  • ISC