openmct/platform/telemetry/src/TelemetryTable.js
Victor Woeltjen 590f4caa97 [Telemetry] Implement subscription pools
Implement data structures which support lossless/lossy
behaviors for telemetry subscriptions (that is, allow
users of the telemetrySubscriber to decide whether or not
they are willing to drop updates in favor of only being
notified with the latest available values.) WTD-784.
2015-01-30 15:36:50 -08:00

53 lines
1.7 KiB
JavaScript

/*global define*/
define(
[],
function () {
"use strict";
/**
* Supports TelemetrySubscription. Provides a simple data structure
* (with a pool-like interface) that aggregates key-value pairs into
* one large object, overwriting new values as necessary. Stands
* in contrast to the TelemetryQueue, which will avoid overwriting
* values.
* @constructor
*/
function TelemetryTable() {
var table;
return {
/**
* Check if any value groups remain in this pool.
* @return {boolean} true if value groups remain
*/
isEmpty: function () {
return !table;
},
/**
* Retrieve the next value group from this pool.
* This gives an object containing key-value pairs,
* where keys and values correspond to the arguments
* given to previous put functions.
* @return {object} key-value pairs
*/
poll: function () {
var t = table;
table = undefined;
return t;
},
/**
* Put a key-value pair into the pool.
* @param {string} key the key to store the value under
* @param {*} value the value to store
*/
put: function (key, value) {
table = table || {};
table[key] = value;
}
};
}
return TelemetryTable;
}
);