Skip to content

Commit

Permalink
batch the events
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Oct 9, 2019
1 parent ffb3f60 commit 33051a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion server/SimpleHIDServer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.vscode/
.vs/
bin/
obj/
packages/
Expand Down
10 changes: 6 additions & 4 deletions src/StreamingListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TimeSeriesMessage } from 'types';
import { TimeSeriesMessage, TimeSeriesValue } from './types';
import { KeyValue, CircularDataFrame, FieldType, LoadingState, DataFrame } from '@grafana/data';
import { Subject, Observable, ReplaySubject } from 'rxjs';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
Expand Down Expand Up @@ -33,8 +33,10 @@ export class StreamListener {
},
});
this.stream!.subscribe({
next: (msg: any) => {
this.process(msg as TimeSeriesMessage);
next: (msg: TimeSeriesMessage) => {
for (const evt of msg.events) {
this.process(evt);
}
},
});
} else {
Expand Down Expand Up @@ -100,7 +102,7 @@ export class StreamListener {
return this.getOrCreate(name).subject;
}

process(msg: TimeSeriesMessage) {
process(msg: TimeSeriesValue) {
const info = this.getOrCreate(msg.name);
const df = info.frame;
if (!df.fields.length) {
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export interface MyDataSourceOptions extends DataSourceJsonData {
apiKey?: string;
}

export interface TimeSeriesMessage {
export interface TimeSeriesValue {
name: string; // Name of the field
config?: FieldConfig; // optionally include field config
time?: number;
value?: any;
}

export interface TimeSeriesMessage {
events: TimeSeriesValue[];
}

0 comments on commit 33051a4

Please sign in to comment.