Tcl Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

defer - Defered execution

Table Of Contents

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

The defer commands allow a developer to schedule actions to happen as part of the current variable scope terminating. This is most useful for dealing with cleanup activities. Since the defered actions always execute, and always execute in the reverse order from which the defer statements themselves execute, the programmer can schedule the cleanup of a resource (for example, a channel) as soon as that resource is acquired. Then, later if the procedure or lambda ends, either due to an error, or an explicit return, the cleanup of that resource will always occur.

COMMANDS

EXAMPLES

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

REFERENCES

AUTHORS

Roy Keene

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category defer of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

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.

KEYWORDS

cleanup, golang

CATEGORY

Utility

COPYRIGHT

Copyright © 2017, Roy Keene