T
tRPC

async inside link next handler possible ?

async inside link next handler possible ?

Aavallete3/14/2023
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 ?

Looking for more? Join the community!

T
tRPC

async inside link next handler possible ?

Join Server