Skip to main content

foundation-store.abstractstore.invokeasyncapi

Home > @genesislcap/foundation-store > AbstractStore > invokeAsyncAPI

AbstractStore.invokeAsyncAPI() method​

A convenience method to invoke an async api and emit success and error events.

Signature:

protected invokeAsyncAPI<TResult>(api: () => Promise<TResult>, error: keyof (TEventDetailMap & TInternalEventDetailMap), success?: keyof (TEventDetailMap & TInternalEventDetailMap)): Promise<void>;

Parameters​

Parameter

Type

Description

api

() => Promise<TResult>

The async service api function.

error

keyof (TEventDetailMap & TInternalEventDetailMap)

The event key from the store fragment's event detail map.

success

keyof (TEventDetailMap & TInternalEventDetailMap)

(Optional) The event key from the store fragment's event detail map.

Returns:

Promise<void>

Remarks​

The async api function should throw when it encounters an error.

Example​

onLoad = this.createAsyncListener('domain-load', async () =>
this.invokeAsyncAPI(
async () => {
!this.domainService.initialized && (await this.domainService.initialize(this.asDomainServiceInit()));
return this.domainService.list();
},
'domain-load-error',
'domain-load-success'
)
);