Skip to content

Commit

Permalink
Trying change to PromiseLike
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanburke committed Jan 15, 2025
1 parent 8e8f8d1 commit ae13603
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ export function Task<T>(
Task.success = <T>(data: T) => AppResult<T>(data)
Task.fail = <T>(error: unknown) => AppException<T>(error)

export type AsyncTask<T> = Promise<Task<T>>
export type AsyncTask<T> = PromiseLike<Task<T>>

export async function AsyncTask<T>(
t: () => T,
e: (error: unknown) => unknown = (error: unknown) => error,
f: () => Promise<void> | void = async () => {},
): AsyncTask<T> {
): Promise<Awaited<T>> {
try {
const result = await t()
return AppResult<T>(result)
return AppResult<Awaited<T>>(result)
} catch (error) {
const errorResult = await e(error)
return AppException<T>(errorResult)
return AppException<Awaited<T>>(errorResult)
} finally {
await f()
}
Expand Down

0 comments on commit ae13603

Please sign in to comment.