in reply to Module callbacks - to fork or not fork

Do the things executing inside the callbacks need to be completed successful before you send back your 2xx status code? If so, then forking won't help because you need to know if those subs succeeded or not.

Replies are listed 'Best First'.
Re^2: Module callbacks - to fork or not fork
by hippo (Archbishop) on Mar 01, 2023 at 10:19 UTC

    Contrarily, if the callbacks don't need to be completed beforehand then you don't necessarily need to fork either: just send your 200 first and then work through the callbacks.


    🦛

      just send your 200 first and then work through the callbacks

      Why didn't I think of that???
      I guess I'm conditioned to doing the logic first, then the output...

      I've not tested it, but could there be a danger that the 200 and its payload will get buffered and will end up waiting after the callbacks complete? I have written code before that outputs HTML to a browser and then does other time-consuming stuff. But the HTML gets stuck in a buffer and I see a 408 timeout error instead of the HTML.

        Yes, that's a possibility but you can take steps to ensure that it doesn't happen. Those steps will depend on which web server you use but will typically involve flushing the output or closing STDIN and STDOUT at a minimum. A little trial and error should get you there.


        🦛