Can a Dispatcher access it's parent Producer methods/attributes?

Can a custom dispatcher made with @behavior GenStage.Dispatcher access its parent modules which invoking him as {:producer, state, dispatcher: CustomDispatcher} ?

I have realized the dispatcher is launched within the same process than the producer.

If I for example try to launch a handle_call from the dispatcher to the producer then I will receive:

GenStage.call(producer, :test)                   
** (exit) exited in: GenServer.call(#PID<0.1575.0>, :test, 5000)
    ** (EXIT) process attempted to call itself
    (elixir) lib/gen_server.ex:917: GenServer.call/3

So having this error, is there any other obvious way to access producer’s methods?

I know you can initialize the dispatcher with params but I would like to access producer methods/state because they are modified withing producer callbacks

How would you expect that to work? Performing a call to yourself would just block, because it’s already running ‘you’, until the timeout elapsed, so it would never work anyway, that is why call’s to self() are blocked. You can always spawn out another process (perfect use for a Task with it’s own supervisor) to do what you need though if it can be done asynchronously, but of course if you need to ‘return’ data then you can’t do that either because it still blocks waiting for that.

2 Likes