Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.callsFake((path: string, method, payload) => {
// For requests we need to store one-time promises
requestPromises[path] = createDeferredPromise();
// in any case, remove the reference after the promise has served its purpose
requestPromises[path]
.then(() => delete requestPromises[path])
.catch(() => delete requestPromises[path])
;
return requestPromises[path];
});
} else {
return __awaiter(this, void 0, void 0, function* () {
if (this.isObserving(endpoints_1.endpoints.groups))
return;
this.observeGroupsPromise = deferred_promise_1.createDeferredPromise();
// We have a timing problem here, as the observeGatewayPromise might be
// rejected in the callback and set to null. Therefore return it before
// starting the observation
void this.observeResource(endpoints_1.endpoints.groups, (resp) => void this.observeGroups_callback(resp)).catch(e => {
// pass errors through
if (!!this.observeGroupsPromise)
this.observeGroupsPromise.reject(e);
});
return this.observeGroupsPromise;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (this.isObserving(endpoints_1.endpoints.devices))
return;
this.observeDevicesPromise = deferred_promise_1.createDeferredPromise();
// We have a timing problem here, as the observeGatewayPromise might be
// rejected in the callback and set to null. Therefore return it before
// starting the observation
void this.observeResource(endpoints_1.endpoints.devices, (resp) => void this.observeDevices_callback(resp)).catch(e => {
// pass errors through
if (!!this.observeDevicesPromise)
this.observeDevicesPromise.reject(e);
});
return this.observeDevicesPromise;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (this.isObserving(endpoints_1.endpoints.gateway(endpoints_1.GatewayEndpoints.Details)))
return;
this.observeGatewayPromise = deferred_promise_1.createDeferredPromise();
// We have a timing problem here, as the observeGatewayPromise might be
// rejected in the callback and set to null. Therefore return it before
// starting the observation
void this.observeResource(endpoints_1.endpoints.gateway(endpoints_1.GatewayEndpoints.Details), (resp) => void this.observeGateway_callback(resp)).catch(e => {
// pass errors through
if (!!this.observeGatewayPromise)
this.observeGatewayPromise.reject(e);
});
return this.observeGatewayPromise;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (this.isObserving(endpoints_1.endpoints.notifications))
return;
this.observeNotificationsPromise = deferred_promise_1.createDeferredPromise();
// We have a timing problem here, as the observeNotificationsPromise might be
// rejected in the callback and set to null. Therefore return it before
// starting the observation
void this.observeResource(endpoints_1.endpoints.notifications, (resp) => void this.observeNotifications_callback(resp)).catch(e => {
// pass errors through
if (!!this.observeNotificationsPromise)
this.observeNotificationsPromise.reject(e);
});
return this.observeNotificationsPromise;
});
}