diff --git a/pwiki/store/base.js b/pwiki/store/base.js index d2f3abf..5ae0935 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -65,6 +65,9 @@ var pwpath = require('../path') // -> // -> // +// NOTE: when a getter is pending (promise), all consecutive calls will +// resolve the original getter return value... +// // // // Special methods: @@ -95,6 +98,9 @@ var pwpath = require('../path') // Modification time... // .___modified // +// Pending generator promise... +// .___promise +// // // Options format: // { @@ -143,6 +149,7 @@ function(name, generate, options={}){ var merge = `__${name}_merge__` var special = `__${name}__` var modified = `__${name}_modified` + var promise = `__${name}_promise` // set modified time... var _stamp = function(that, res){ @@ -160,17 +167,19 @@ function(name, generate, options={}){ var _smake = function(that){ return _stamp(that, _make(that)) } // unwrap a promised value into cache... - var promise = `__${name}_promise` var _await = function(obj, val){ if(val instanceof Promise){ // NOTE: this avoids a race condition when a getter is called // while a previous getter is still pending... - val = obj[promise] = - obj[promise] - ?? val - val.then(function(value){ - delete obj[promise] - obj[cache] = value }) } + if(obj[promise] == null){ + obj[promise] = val + val.then( + function(value){ + delete obj[promise] + obj[cache] = value }, + function(){ + delete obj[promise] }) } + val = obj[promise] } return val } // build the method...