smartuniverse/ts/smartuniverse.classes.universemessage.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-03-13 05:15:40 +00:00
import * as plugins from './smartuniverse.plugins';
import { Timer, TimeStamp } from 'smarttime';
import { UniverseStore } from './smartuniverse.classes.universestore';
2018-04-13 13:45:48 +00:00
/**
* represents a message within a universe
*/
2018-03-13 05:15:40 +00:00
export class UniverseMessage {
/**
* public and unique id
* numeric ascending
* adheres to time in milliseconds
* avoids duplications though
*/
public id: number;
public universeStore: UniverseStore;
public timestamp: TimeStamp;
public message: string;
public attachedPayload: any;
public destructionTimer: Timer;
2018-03-20 07:16:54 +00:00
constructor(
parentUniverseStore: UniverseStore,
messageArg: string,
attachedPayloadArg: any,
selfdestructAfterArg: number
) {
2018-03-13 05:15:40 +00:00
this.universeStore = parentUniverseStore;
this.timestamp = new TimeStamp();
this.message = messageArg;
this.attachedPayload = attachedPayloadArg;
2018-03-20 07:16:54 +00:00
this.destructionTimer = new Timer(selfdestructAfterArg);
this.destructionTimer.start();
2018-03-13 05:15:40 +00:00
// set up self destruction by removing this from the parent messageStore
this.destructionTimer.completed.then(async () => {
this.universeStore.messageStore.remove(this);
2018-03-20 07:16:54 +00:00
});
2018-03-13 05:15:40 +00:00
}
}