class InstructionResultSourceFactory implements InstructionResultSource.Factory {

    @Override
    public InstructionResultSource onInstructionResultFor(String instructionId) {
        return new InstructionResultSource() {

            @Override
            public void subscribe(ResultSubscriber resultSubscriber, Duration timeout) {
                Function<String, List<ResultSubscriber>> copyOnWriteArrayList = id -> new CopyOnWriteArrayList<>();
                List<ResultSubscriber> subscribers = subscribersMap.computeIfAbsent(instructionId,
                                                                                    copyOnWriteArrayList);
                subscribers.add(new TimeoutResultSubscriber(resultSubscriber, timeout, subscribers::remove));
            }

            @Override
            public Duration defaultTimeout() {
                return Duration.ofSeconds(resultTimeout);
            }
        };
    }

    @Autowired public  InstructionResultSourceFactory(PlatformService platformService,
                                          @Value("${axoniq.axonserver.instruction.result.timeout:10}") int resultTimeout);
    public  InstructionResultSourceFactory(Consumer<Consumer<InstructionResult>> registration,
                                          int resultTimeout);

}