async callbacks
nikolasdas opened this issue · comments
Any plans for defineCronHandler
to accept an async CronTick
callback? Would be very helpful! :)
Now you can use asynchronous callbacks.
import { defineCronHandler } from '#nuxt/cron'
export default defineCronHandler('everyMinute', async () => {
const data = await $fetch<{ repos: any[] }>('https://ungh.cc/orgs/unjs/repos')
console.log(`UnJS has ${data.repos.length} repositories available`)
}, { runOnInit: true })
// stdOut: UnJS has 88 repositories available
If it doesn't make sense to you, write a case study.
Sorry I should have clarified this a bit more, passing a async callback seems to work fine, yes.
But the type definition requires a sync function, would it be possible to change this?
Can you give me an example, I guess I don't understand what you're talking about.
nuxt-cron/src/runtime/types.d.ts
Line 24 in b69fcc2
Because of this type definition I get a
@typescript-eslint/no-misused-promises
warning. I know this might be nitpicky, but I try to have my eslint rules strict and avoid eslint-disable comments 🙈I can create a PR if you'd like, but wanted to make sure it is okay to use an async function in the first place
Looked at the types, I can replace CronTick
export type CronTick = () => void | Promise<void>
Am I correct in assuming that's what you're looking for?
Yes, this would make my linter and subsequently me happier 👍
Thank you for your awesome support! And this cool nuxt module of course :)