GOLF(2gg)
π 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-oncecannot be nested β nodo-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
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms