How to `eval` a command instantly?
You can run the function from a command block and in the function you can modify a command block later in the chain.
For example, I just tested this:
Regular command block that points into the chain command block: function test:test
Function file: data merge block <coordinates> {Command:"say a"}
with the coordinates of the chain command block
Chain command block: say test
I activated the regular command block and the output was:
[@: Executed 1 commands from function 'test:test']
[@] a
And since it's a command block chain, everything happened in the same tick.
Note that it's impossible to run a function in a new thread or to do anything else in the middle of a function that you didn't specify in the function itself, because the function (and all the functions it calls) are executed as soon as possible, pausing everything else on the server in the meantime. It's true that some actions, like summoning entities, has effects that can be detected rightaway in the function, but none of those things can execute an arbitrary command instantly:
- setting a command block to
auto:1
(even the same one that ran the function) - placing an always active command block
- summoning a command block minecart on an activator rail
- setting an activator rail at a command block minecart All these actions are triggered after the function ends (or even later, in the case of the command block minecart). There's also no command that executes an arbitrary command based on a string that is stored somewhere, at least in Vanilla. It was suggested and the developers have considered it, but so far only a mod adds it.
So the best you can currently do is to run the command that changes the chain command block's data as the last command in the function (or function call chain) and then do everything later in another function, triggered by another chain command block after that.