const stack = [ ] ; export function getCurrent < T > ( ) { if ( ! stack . length ) { throw new Error ( 'Do not get current out of wrap function.' ) ; } return stack [ stack . length - 1 ] ; } export function wrap < R > ( globalCache , fn ) { stack . push ( globalCache ) ; try { return fn ( ) ; } catch ( e ) { throw e ; } finally { stack . pop ( ) ; } }