-
-
Notifications
You must be signed in to change notification settings - Fork 205
feat(cdk): add rxScheduleTask function #1344
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
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 4aa53ee. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
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.
hi @Karnaukhov-kh very nice PR, i like the idea a lot! Left some thoughts in the comments
export const rxScheduleTask = ( | ||
work: (...args: any[]) => void, | ||
strategy: keyof StrategiesPriorityRecord = 'normal', | ||
options?: { | ||
delay?: number; | ||
ngZone?: NgZone; | ||
} | ||
) => { | ||
const task = scheduleCallback( | ||
strategiesPrio[strategy], | ||
() => work(), | ||
options | ||
); | ||
return () => { | ||
cancelCallback(task); | ||
}; | ||
}; |
There 8000 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.
why don't we provide an observable version of this standalone function as well?
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.
Isn't scheduleOnQueue
already an operator that uses it, but with coalescing?
*/ | ||
export const rxScheduleTask = ( | ||
work: (...args: any[]) => void, | ||
strategy: keyof StrategiesPriorityRecord = 'normal', |
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.
How would a user use the function with a custom strategy? the typing wouldn't allow it currently. Or am I missing something?
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 guess we should not use custom strategy here, because only thing we need from strategy is priority. And scheduler not working with custom priority levels.
That's why we need this ⬇️, to provide users familiar API instead of PriorityLevel
enum.
const strategiesPrio: StrategiesPriorityRecord = {
immediate: PriorityLevel.ImmediatePriority,
userBlocking: PriorityLevel.UserBlockingPriority,
normal: PriorityLevel.NormalPriority,
low: PriorityLevel.LowPriority,
idle: PriorityLevel.IdlePriority,
};
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.
Nice work, I would add some unit tests to see if the scheduleCallback
is correctly called. I think that render-strategies
is not the right place to expose that fn, but I can't figure out a better place.
Thank you for feedback @hoebbelsB @edbzn, I'll answer and apply changes soon :). |
Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>
export const rxScheduleTask = ( | ||
work: (...args: any[]) => void, | ||
8000 options?: { | ||
strategy?: keyof StrategiesPriorityRecord; | ||
delay?: number; | ||
ngZone?: NgZone; | ||
} | ||
) => { | ||
const task = scheduleCallback( | ||
strategiesPrio[options?.strategy || defaultStrategy], | ||
() => work(), | ||
{ | ||
delay: options?.delay, | ||
ngZone: options?.ngZone, | ||
} | ||
); | ||
return () => { | ||
cancelCallback(task); | ||
}; | ||
}; |
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.
What about the following syntax to initialize options?
export const rxScheduleTask = ( | |
work: (...args: any[]) => void, | |
options?: { | |
strategy?: keyof StrategiesPriorityRecord; | |
delay?: number; | |
ngZone?: NgZone; | |
} | |
) => { | |
const task = scheduleCallback( | |
strategiesPrio[options?.strategy || defaultStrategy], | |
() => work(), | |
{ | |
delay: options?.delay, | |
ngZone: options?.ngZone, | |
} | |
); | |
return () => { | |
cancelCallback(task); | |
}; | |
}; | |
export const rxScheduleTask = ( | |
work: (...args: any[]) => void, | |
{ | |
strategy = defaultStrategy, | |
delay, | |
ngZone, | |
}: { | |
strategy?: keyof StrategiesPriorityRecord; | |
delay?: number; | |
ngZone?: NgZone; | |
} = {} | |
) => { | |
const task = scheduleCallback(strategiesPrio[strategy], () => work(), { | |
delay, | |
ngZone, | |
}); | |
return () => { | |
cancelCallback(task); | |
}; | |
}; |
Closing in favor of #1633 |
Introduces
rxScheduleTask
function to schedule tasks with our scheduler.