defer(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ defer β€” bestie we are doing CLEANUP ✨

okay so this is defer(3tcl) from the tcllib manual set, and it is literally the "defered execution ala Go" page. yes the typo is canon, we respect it πŸ’…


🌸 NAME 🌸

defer β€” Defered execution. that's it, that's the name, she's simple and she serves 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

package require Tcl 8.6 9

package require defer ?1.1?

::defer::defer ?command? ?arg1? ?arg2? ?argN...?

::defer::with variableList script

::defer::autowith script

::defer::cancel ?id...?

πŸ’– DESCRIPTION πŸ’–

so the defer commands let you, the developer, schedule actions to happen as part of the current variable scope terminating. it's giving cleanup-activity energy, and honestly that's the whole point.

the way this hits: because the defered actions always execute, and they always execute in the reverse order from which the defer statements themselves execute, you can schedule the cleanup of a resource (say, a channel, bestie) the second you acquire it. then, later, if the procedure or lambda ends β€” whether that's because of an error, or an explicit return β€” the cleanup of that resource will always occur. no cap. that's the whole vibe. 😭✨


πŸ‘‘ COMMANDS πŸ‘‘

  • ::defer::defer ?command? ?arg1? ?arg2? ?argN...? β€” defers execution of some code until the current variable scope ends. every argument gets concatenated together to form the script that runs at deferal time. you can use multiple defer statements and they execute last-in, first-out. the return value is an identifier, and you can hand that identifier to defer::cancel later. πŸ’…
  • ::defer::with variableList script β€” defers execution of a script, but it copies the current value of some variables into the script β€” the names of those variables are the ones you list in variableList. the script acts like a lambda, but it executes at the same level as the defer::with call. the return value is the same as ::defer::defer. πŸŽ€
  • ::defer::autowith script β€” same as ::defer::with, except it uses all local variables in the variable list. lazy girl behavior and we love her for it 🌸
  • ::defer::cancel ?id...? β€” cancels the execution of a defered action. the id argument is the identifier returned by ::defer::defer, ::defer::with, or ::defer::autowith. you can supply any number of arguments, and all of the IDs supplied will be cancelled. periodt. ✨

🌈 EXAMPLES 🌈

package require defer 1
apply {{} {
   set fd [open /dev/null]
   defer::defer close $fd
}}

look at her go πŸ¦‹ open the fd, immediately schedule the close, let the scope do the rest. iconic behavior fr fr.


πŸ“š REFERENCES πŸ“š

[1]


πŸ’œ AUTHORS πŸ’œ

Roy Keene πŸ‘‘


πŸ™ˆ BUGS, IDEAS, FEEDBACK πŸ™ˆ

ngl, this document, and the package it describes, will undoubtedly contain bugs and other problems. so please report such in the category defer of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you may have for either the package and/or the documentation β€” we want all of it, bestie 🫢

when proposing code changes, please provide unified diffs, i.e the output of diff -u. yes literally that.

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk πŸ’…


πŸŽ€ KEYWORDS πŸŽ€

cleanup, golang


⭐ CATEGORY ⭐

Utility


Copyright (c) 2017, Roy Keene


okay that's the whole page, mwah πŸ’‹ this was the defer(3tcl) manpage from tcllib, version 1.1 β€” go forth and clean up your resources, bestie, you've got this 🌈✨🫢

πŸ“¦ where this page comes from