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.
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
/*global define*/
|
|
|
|
define(
|
|
["./TelemetrySubscription"],
|
|
function (TelemetrySubscription) {
|
|
"use strict";
|
|
|
|
/**
|
|
* The TelemetrySubscriber is a service which allows
|
|
* subscriptions to be made for new data associated with
|
|
* domain objects. It is exposed as a service named
|
|
* `telemetrySubscriber`.
|
|
*
|
|
* Subscriptions may also be made directly using the
|
|
* `telemetry` capability of a domain objcet; the subscriber
|
|
* uses this as well, but additionally handles delegation
|
|
* (e.g. for telemetry panels) as well as latest-value
|
|
* extraction.
|
|
*
|
|
* @constructor
|
|
* @param $q Angular's $q
|
|
* @param $timeout Angular's $timeout
|
|
*/
|
|
function TelemetrySubscriber($q, $timeout) {
|
|
return {
|
|
/**
|
|
* Subscribe to streaming telemetry updates
|
|
* associated with this domain object (either
|
|
* directly or via capability delegation.)
|
|
*
|
|
* @param {DomainObject} domainObject the object whose
|
|
* associated telemetry data is of interest
|
|
* @param {Function} callback a function to invoke
|
|
* when new data has become available.
|
|
* @param {boolean} lossless flag to indicate whether the
|
|
* callback should be notified for all values
|
|
* (otherwise, multiple values in quick succession
|
|
* will call back with only the latest value.)
|
|
* @returns {TelemetrySubscription} the subscription,
|
|
* which will provide access to latest values.
|
|
*
|
|
* @method
|
|
* @memberof TelemetrySubscriber
|
|
*/
|
|
subscribe: function (domainObject, callback, lossless) {
|
|
return new TelemetrySubscription(
|
|
$q,
|
|
$timeout,
|
|
domainObject,
|
|
callback,
|
|
lossless
|
|
);
|
|
}
|
|
};
|
|
}
|
|
|
|
return TelemetrySubscriber;
|
|
}
|
|
); |