node.js - RxJs How to Observe object property change -
i'm running issue. have client instantiates has ready boolean property. want wait until switches true resolve promise. tried lot of different ways including while loop blocks thread without checking updates.
here's attempt
var startclient = function() { return new promise((resolve, reject)=> { var client = createclient(); while(!client.ready) {} resolve(client); }); };
my question is: there way use rxjs help.. maybe emit , event if ready property changed? below more pseudo code i'm trying do.
var startclient = function() { return new promise((resolve, reject)=> { var client = createclient(); var emitter = observable.watch(client, 'ready'); emitter.on('ready', function(result) { if(result) resolve(client); }); };
any suggestions? thanks!
if can, overwrite ready
property on client trap assignments it, follows:
// check if ready flag set. if (client.ready) return resolve(client); let _ready; object.defineproperty(client, 'ready', { // trap assignment , resolve if true. set(b) { _ready = b; if (b) resolve(client); }, // politely provider getter in case else trying access it. get() { return _ready; } });
this won't work if property not configurable, or object frozen, etc.
Comments
Post a Comment