import { Runnable } from './Runnable'; export abstract class RunnableLoader implements Runnable> { protected loaded?: T; public run(...params: any[]): Promise { return this.load() .then(it => { this.loaded = it; this.completed(this.loaded); return it; }) .catch(e => { this.error(e); throw e; }); } stop() { this.unload(this.loaded); } protected abstract load(): Promise; protected abstract unload(installed?: T): Promise; protected abstract completed(installed: T): Promise; protected abstract error(e: any): Promise; }