refactor: unify streaming
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -268,22 +268,29 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
* @param secret - optional secret for discovery
|
||||
* @param location - optional location for discovery
|
||||
* @param provider - optional provider identifier for discovery
|
||||
* @param onService - called for each discovered service as it arrives
|
||||
*
|
||||
* @returns Promise with list of discovered service objects
|
||||
* @returns Promise resolving to { total } when the stream completes
|
||||
*/
|
||||
async function discover(
|
||||
identity: string,
|
||||
secret: string | undefined,
|
||||
location: string | undefined,
|
||||
provider: string | undefined,
|
||||
): Promise<ServiceObject[]> {
|
||||
onService?: (service: ServiceObject) => void,
|
||||
): Promise<{ total: number }> {
|
||||
transceiving.value = true
|
||||
|
||||
try {
|
||||
const services = await serviceService.discover({identity, secret, location, provider})
|
||||
const result = await serviceService.discover(
|
||||
{ identity, secret, location, provider },
|
||||
(service: ServiceObject) => {
|
||||
onService?.(service)
|
||||
}
|
||||
)
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully discovered', services.length, 'services')
|
||||
return services
|
||||
console.debug('[Mail Manager][Store] - Successfully discovered', result.total, 'services')
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to discover service:', error)
|
||||
throw error
|
||||
|
||||
Reference in New Issue
Block a user