/// Handles an incoming `Invocation`.
fn handle(&mut self, env: InvocEnv) {
match self.decide(&env.0) {
RunDecision::PutAway => {
trace!("WasmPool could not handle invocation right away, putting away.");
self.outstanding_invocations.push(env);
},
RunDecision::Forward(i) => {
trace!("WasmPool found a free executor at #{}, invoking.", i);
self.executors[i].invoke((env.0.payload, env.1));
},
RunDecision::SpawnNew => {
trace!("WasmPool decided to spawn a new executor #{} for the current invocation.", self.n_executors);
self.executors.push(
Executor::new(
self.n_executors,
env.0.owner,
env.0.app_name)
);
self.n_executors += 1;
},
RunDecision::Replace(i) => {
trace!("WasmPool decided to replace the code in executor #{} before using it to handle an invocation.", i);
self.executors[i].load_code(vec![]); // TODO: actually load the code.
self.executors[i].owner = env.0.owner;
self.executors[i].app_name = env.0.app_name;
self.executors[i].invoke((env.0.payload, env.1));
}
}
}
}\