GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸŽ€ GOLF(2gg) β€” do-once, bestie πŸŽ€

okay so we're in the GOLF(2gg) part of the manual (the Development section, iykyk), and today's main character is a lil program-flow icon called do-once. Let's get into it πŸ’…


✨ NAME ✨

do-once β€” (program-flow) πŸ¦‹


🌸 PURPOSE 🌸

Run statements exactly once in a process. No cap. One time. That's the whole vibe. ✨


πŸŽ€ SYNTAX πŸŽ€

     do-once
        <any statements>
        ...
     end-do-once

literally that's it, she's simple but she's powerful πŸ’œ


πŸ’– DESCRIPTION πŸ’–

do-once will execute <any statements> only once in a single process β€” no matter how many requests that process ends up serving. The <any statements> wrap up with end-do-once.

So the first time a process reaches do-once, those <any statements> run. Every single time after that? The program control just skips right on past to immediately after end-do-once. Not me ghosting the block after the first visit πŸ’€

Things to know, bestie:

  • do-once cannot be nested β€” no do-once-ception, we don't do that here 🚫
  • But otherwise? Use it as many times as you want, she's flexible like that πŸ’…

Typical use cases β€” like, what is she even for:

  • Making any calls that need to be performed only once per process
  • One-time setup of process-scoped variables
  • Anything else that needs to execute just once for all the requests served by the same process

Scope tea β˜•: <any statements> execute in the nested scope relative to the code surrounding do-once/end-do-once β€” except that any process-scoped variables are created in the same scope as the code surrounding do-once/end-do-once. Which, lowkey, just simplifies creation of process-scoped variables if you need them. Convenient? Iconic. πŸ‘‘


πŸ¦‹ EXAMPLES πŸ¦‹

Okay so in this example, a process-scoped hash (that is available to multiple requests of a single process) gets created in the very first request a process serves, and data gets written to it. The subsequent requests do not create a new hash β€” they just write to the one that's already there. Main character hash energy fr fr 🌈

     ...
      do-once
         new-hash my_hash hash-size 1024 process-scope
      end-do-once
      write-hash my_hash key my_key value my_data
      ...

πŸ’œ SEE ALSO πŸ’œ

Program flow 🌸

break-loop call-handler code-blocks continue-loop do-once exit-handler if-defined if-true quit-process return-handler start-loop β€” See all documentation 🫢


periodt. that's the whole page, go forth and execute things exactly once bestie πŸ§šβ€β™€οΈβœ¨

this page was brought to you by $VERSION, dated $DATE, living its best life under the GOLF(2gg) banner πŸ’– tysm for reading, ily, bye!! πŸŽ€

πŸ“¦ where this page comes from