Skip to content

Commit

Permalink
Force post notification job callback to static lifetime (#357)
Browse files Browse the repository at this point in the history
Post notification job callback is kept by Redis for unknown time and so we must force it live for the static lifetime. Notice that this does not mean that the value must live forever, it just means that it can not hold any none static references. For more information: https://practice.rs/lifetime/static.html#t-static
  • Loading branch information
MeirShpilraien authored Jul 25, 2023
1 parent 96f814b commit e791067
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,10 @@ impl Context {
/// as a logical bug that need to be fixed in the module, an attempt to protect against
/// infinite loops by halting the execution could result in violation of the feature correctness
/// and so Redis will make no attempt to protect the module from infinite loops.
pub fn add_post_notification_job<F: FnOnce(&Context)>(&self, callback: F) -> Status {
pub fn add_post_notification_job<F: FnOnce(&Context) + 'static>(
&self,
callback: F,
) -> Status {
let callback = Box::into_raw(Box::new(Some(callback)));
unsafe {
RedisModule_AddPostNotificationJob(
Expand Down

0 comments on commit e791067

Please sign in to comment.