1defer(n)                   Defered execution ala Go                   defer(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       defer - Defered execution
9

SYNOPSIS

11       package require Tcl  8.6
12
13       package require defer  ?1?
14
15       ::defer::defer ?command? ?arg1? ?arg2? ?argN...?
16
17       ::defer::with variableList script
18
19       ::defer::autowith script
20
21       ::defer::cancel ?id...?
22
23______________________________________________________________________________
24

DESCRIPTION

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

COMMANDS

37       ::defer::defer ?command? ?arg1? ?arg2? ?argN...?
38              Defers  execution  of some code until the current variable scope
39              ends.  Each argument  is  concatencated  together  to  form  the
40              script  to  execute  at deferal time.  Multiple defer statements
41              may be used, they are executed in the order of  last-in,  first-
42              out.   The return value is an identifier which can be used later
43              with defer::cancel
44
45       ::defer::with variableList script
46              Defers execution of a script while copying the current value  of
47              some  variables, whose names specified in variableList, into the
48              script.  The script acts like a lambda but executes at the  same
49              level  as the defer::with call.  The return value is the same as
50              ::defer::defer
51
52       ::defer::autowith script
53              The same as ::defer::with but uses all local  variables  in  the
54              variable list.
55
56       ::defer::cancel ?id...?
57              Cancels  the  execution of a defered action.  The id argument is
58              the identifier returned  by  ::defer::defer,  ::defer::with,  or
59              ::defer::autowith.  Any number of arguments may be supplied, and
60              all of the IDs supplied will be cancelled.
61

EXAMPLES

63                package require defer 1
64                apply {{} {
65                   set fd [open /dev/null]
66                   defer::defer close $fd
67                }}
68
69

REFERENCES

71       [1]
72

AUTHORS

74       Roy Keene
75

BUGS, IDEAS, FEEDBACK

77       This document, and the package it describes, will  undoubtedly  contain
78       bugs  and  other problems.  Please report such in the category defer of
79       the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please
80       also  report any ideas for enhancements you may have for either package
81       and/or documentation.
82
83       When proposing code changes, please provide unified diffs, i.e the out‐
84       put of diff -u.
85
86       Note  further  that  attachments  are  strongly  preferred over inlined
87       patches. Attachments can be made by going  to  the  Edit  form  of  the
88       ticket  immediately  after  its  creation, and then using the left-most
89       button in the secondary navigation bar.
90

KEYWORDS

92       cleanup, golang
93

CATEGORY

95       Utility
96
98       Copyright (c) 2017, Roy Keene
99
100
101
102
103tcllib                                 1                              defer(n)
Impressum