in reply to Re: Module callbacks - to fork or not fork
in thread Module callbacks - to fork or not fork

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.


🦛

  • Comment on Re^2: Module callbacks - to fork or not fork

Replies are listed 'Best First'.
Re^3: Module callbacks - to fork or not fork
by Bod (Parson) on Mar 01, 2023 at 23:16 UTC
    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.


      🦛