Skip to content

Commit

Permalink
[#108] Support mocks running a background task
Browse files Browse the repository at this point in the history
Allow patching a mocked call that is running in an older world age by changing the macro to invoke the patch through `invokelatest`.

The call was already inherently going to be a dynamic dispatch anyway, since by definition the whole point is that we want to substitute in a new function later. Invokelatest will just allow us to substitute in a function that was even _defined_ later, after this function had started running.

This doesn't add any extra overhead, nor introduce any restrictions. The only thing that it does is increase the scenarios that Mocking supports.
  • Loading branch information
NHDaly authored May 23, 2023
1 parent 06392c4 commit a4b105c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/mock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro mock(expr)
local $args_var = tuple($(args...))
local $alternate_var = Mocking.get_alternate($target, $args_var...)
if $alternate_var !== nothing
$alternate_var($args_var...; $(kwargs...))
Base.invokelatest($alternate_var, $args_var...; $(kwargs...))
else
$target($args_var...; $(kwargs...))
end
Expand Down

0 comments on commit a4b105c

Please sign in to comment.