[ Previous ] [ Contents ] [ Index ] [ Next ]

ns_atclose

Overview

Register a script to be executed when the current connection closes

Syntax

ns_atclose {script | procname ?args?}

Description

ns_atclose adds the specified script or procedure (procname) to a list of scripts that are invoked when the current connection ends. The scripts are invoked in the reverse order in which they were registered. The scripts still get run if the connection closes early, or if there are Tcl errors following the script registration. If ns_atclose is invoked within a scheduled procedure, the atclose handler is invoked at the end of each scheduled execution of the procedure.

Examples

This example makes a temporary file that gets deleted when the connection ends:

      proc show_at_close { } {
        set tmpfile [ns_tmpnam]
        # open tmpfile, write stuff to it and close it
        ns_atclose "ns_unlink -nocomplain $tmpfile"
        return $tmpfile
      } ;# show_at_close

This example shows ns_atclose being used within a scheduled procedure. Every ten seconds, a temp file will be created, an action will be performed on it, and the ns_atclose handler will delete it:

      ns_schedule_proc 10 recurring_proc
      proc recurring_proc { } {
        set tmpfile [ns_tmpnam]
        ns_atclose "ns_unlink -nocomplain $tmpfile"
        # open tmpfile, write stuff to it.  Do something with the
            # file like use it for an attachment to mail, or something 
        # of that sort
      } ;# recurring_proc

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.