avallete
avallete2y ago

async inside link next handler possible ?

Hey everyone, Today I had to do a bit of refactor, and I'm wondering something. I had to turn a synchronous function into an asynchronous one, and ended up needing async into the trpc "link" like so:
// From
const link: TRPCLink<CLIRouterType> = () => {
return ({ prev, next, op }) => {
next(op, (result) => {
if (is401Error(result)) {
synchronousFunction(result)
}
prev(result)
})
}
}

// to
const link: TRPCLink<CLIRouterType> = () => {
return ({ prev, next, op }) => {
next(op, async (result) => {
if (is401Error(result)) {
await asynchronousFunction(result)
}
prev(result)
})
}
}
// From
const link: TRPCLink<CLIRouterType> = () => {
return ({ prev, next, op }) => {
next(op, (result) => {
if (is401Error(result)) {
synchronousFunction(result)
}
prev(result)
})
}
}

// to
const link: TRPCLink<CLIRouterType> = () => {
return ({ prev, next, op }) => {
next(op, async (result) => {
if (is401Error(result)) {
await asynchronousFunction(result)
}
prev(result)
})
}
}
Is that okay to do so? Turn the callback of next into an async ?
0 Replies
No replies yetBe the first to reply to this messageJoin