@@ -337,6 +337,7 @@ studio.internal = (function(proto) {
337337 var childMap = new Map ( ) ;
338338 var givenPromises = new Map ( ) ;
339339 var childIterators = [ ] ;
340+ var valuePromises = [ ] ;
340341 var valueSubscriptions = [ ] ;
341342 var structureSubscriptions = [ ] ;
342343 var eventSubscriptions = [ ] ;
@@ -446,6 +447,10 @@ studio.internal = (function(proto) {
446447
447448 this . receiveValue = function ( nodeValue , nodeTimestamp ) {
448449 lastValue = nodeValue ;
450+ for ( var i = 0 ; i < valuePromises . length ; i ++ ) {
451+ valuePromises [ i ] ( lastValue ) ;
452+ valuePromises . splice ( i , 1 ) ;
453+ }
449454 for ( var i = 0 ; i < valueSubscriptions . length ; i ++ ) {
450455 valueSubscriptions [ i ] [ 0 ] ( nodeValue , nodeTimestamp ) ;
451456 }
@@ -534,6 +539,14 @@ studio.internal = (function(proto) {
534539 //when offline must queue or update pending set request and call set callbacks ...???
535540 } ;
536541
542+ this . async . requestValue = function ( ) {
543+ let promise = new Promise ( function ( resolve , reject ) {
544+ valuePromises . push ( resolve ) ;
545+ } ) ;
546+ app . makeGetterRequest ( id , 0 , 0 , false ) ;
547+ return promise ;
548+ } ;
549+
537550 this . async . _makeGetterRequest = function ( ) {
538551 if ( valueSubscriptions . length > 0 ) {
539552 var maxFs = Math . max . apply ( Math , valueSubscriptions . map ( v => v [ 1 ] ) ) ;
@@ -658,6 +671,10 @@ studio.internal = (function(proto) {
658671 }
659672 } ;
660673
674+ this . async . requestValue = function ( ) {
675+
676+ } ;
677+
661678 this . async . subscribeToValues = function ( valueConsumer , fs = 5 , sampleRate = 0 ) {
662679
663680 } ;
@@ -830,7 +847,9 @@ studio.internal = (function(proto) {
830847 var msg = new proto . Container ( ) ;
831848 var request = new proto . ValueRequest ( ) ;
832849 request . node_id = id ;
833- request . fs = fs ;
850+ if ( fs ) {
851+ request . fs = fs ;
852+ }
834853 if ( sampleRate ) {
835854 request . sample_rate = sampleRate ;
836855 }
@@ -1107,6 +1126,7 @@ studio.api = (function(internal) {
11071126 this . info = function ( ) {
11081127 return node . info ( ) ;
11091128 } ;
1129+
11101130 /**
11111131 * Access the last known value.
11121132 *
@@ -1190,6 +1210,15 @@ studio.api = (function(internal) {
11901210 * @param {number } timestamp
11911211 */
11921212
1213+ /**
1214+ * Fetch current value.
1215+ *
1216+ * @returns {Promise.<number> } A promise containing fetched value when fulfilled.
1217+ */
1218+ this . requestValue = function ( ) {
1219+ return node . async . requestValue ( ) ;
1220+ } ;
1221+
11931222 /**
11941223 * Subscribe to value changes on this node.
11951224 *
@@ -1433,3 +1462,4 @@ studio.api = (function(internal) {
14331462export default studio
14341463
14351464
1465+
0 commit comments