import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class UpdateService { constructor() { } private async_actions: Array<() => Promise> = []; private actions: Array<() => void> = []; addAsync(action: () => Promise): void { this.async_actions.push(action); } add(action: () => void): void { this.actions.push(action); } removeAll(): void { this.async_actions = []; } async executeAll(): Promise { await Promise.all(this.async_actions.map(action => action())); this.actions.forEach(action => action()); this.removeAll(); } }