import { isUndefined } from 'lodash' ; let locks = { } ; let counter = { } ; export function limitConcurency ( name ) { if ( isUndefined ( locks [ name ] ) ) { locks [ name ] = false ; counter [ name ] = 0 ; } return ( context ) => { counter [ name ] ++ ; function lockGetterSetter ( lock ? ) { if ( typeof lock !== 'undefined' ) { if ( lock === false ) { counter [ name ] -- ; } locks [ name ] = lock ; } else { return locks [ name ] ; } } return context ( lockGetterSetter ) ; } ; }