-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(deno): Refactor deno integrations to use functional syntax #9929
Conversation
size-limit report 📦
|
8b2b578
to
2d20567
Compare
} | ||
|
||
async function cronCalled(): Promise<void> { | ||
if (getClient() !== client) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timfish checking this here to make sure this is only applies if this is the current client, otherwise it may send a monitor to a different client I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of me was thinking that you might still need to call fn()
rather than return but now I'm not sure.
I'm struggling to get my head around how it'll all behave if wrapped multiple times 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch should be done once, not per client, because it proxies the global Deno.cron
function, but we still need the getClient() !== client
so that monitors from clients with the integration get sent.
Can we check if client has integration installed and check accordingly?
We might have to audit all of our integrations for this behaviour now that I think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually rewritten most of them this way, but you're right, it makes more sense this way here too - will follow the same as I did in other PRs already!
2d20567
to
b649c94
Compare
b649c94
to
ad1ec1e
Compare
const denoCronIntegration = (() => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setupOnce() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AbhiPrasad / @timfish , ok, hopefully final refactor here - now this registers once in setupOnce
, and registers the client in setup
, which we check for in here!
|
||
async function cronCalled(): Promise<void> { | ||
if (SETUP_CLIENTS.includes(getClient() as Client)) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we still want to call fn
here?
import { parseScheduleToString } from './deno-cron-format'; | ||
|
||
type CronOptions = { backoffSchedule?: number[]; signal?: AbortSignal }; | ||
type CronFn = () => void | Promise<void>; | ||
// Parameters<typeof Deno.cron> doesn't work well with the overloads 🤔 | ||
type CronParams = [string, string | Deno.CronSchedule, CronFn | CronOptions, CronFn | CronOptions | undefined]; | ||
|
||
const INTEGRATION_NAME = 'DenoCron'; | ||
|
||
const SETUP_CLIENTS: Client[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that clients dont get GC'd - I wonder if we should track with a WeakMap instead?
Refactors deno integrations to functional syntax.