How do you pass a Callback as a parameter?

Hey, it looks like this will be supported in the future but in the meantime the workaround I’ve found is this:

callback_param_handler := class():

    Callback: agent -> void

    On(Agent: agent): void = Callback(Agent)


trigger_zone := class():

    MutatorZoneDevice: mutator_zone_device = mutator_zone_device{}

    var EventAgentEntersCancellation: ?cancelable = false

    RegisterOnAgentEnters(Callback: agent -> void):void=

        set EventAgentEntersCancellation = option{MutatorZoneDevice.AgentEntersEvent.Subscribe(callback_param_handler{Callback:=Callback}.On)}

I couldn’t find a way to make that handler class use a generic type so you need one for every callback signature but it does work.

1 Like