[racket] Callback on shutdown

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun May 4 16:11:53 EDT 2014

Sounds to me like you want to wire into the custodian facilities (via
the ffi I believe) but probably starting with just atexit() itself is
okay.

Robby

On Sun, May 4, 2014 at 3:08 PM, Tony Garnock-Jones <tonyg at ccs.neu.edu> wrote:
> On 05/04/2014 03:55 PM, Spencer Florence wrote:
>> Would something like dynamic-wind work for you?
>> http://docs.racket-lang.org/reference/cont.html?q=dynamic-wind#%28def._%28%28quote._~23~25kernel%29._dynamic-wind%29%29
>
> Thanks for the suggestion, but unfortunately that won't work for me: the
> idea is to be able to write, in client code (rather than library code)
>
>   (start-some-background-service)
>   ...
>   ...
>   (use-background-service-repeatedly)
>   ...
>   ...
>
> and not have to explicitly (shutdown-background-service-cleanly).
>
> This becomes particularly important when the service is used by multiple
> libraries, from multiple threads.
>
> An example of this kind of service is Racket's logging facility. If you
> had to (shutdown-logging!) explicitly, there'd either be boilerplate in
> every program, or a lot of unnecessary shutdowning-and-restarting as
> each library tried to guess an appropriate moment.
>
> Regards,
>   Tony
>
>
>>
>>
>> On Sun, May 4, 2014 at 2:29 PM, Tony Garnock-Jones <tonyg at ccs.neu.edu
>> <mailto:tonyg at ccs.neu.edu>> wrote:
>>
>>     Hi all,
>>
>>     I'm looking for an atexit()-like facility for Racket.
>>
>>     I've tried setting the exit-handler, but it only seems to be called when
>>     I explicitly call exit, and not implicitly when Racket shuts down when
>>     control flows off the end of the main program.
>>
>>     The problem I'm facing is to buffer rows to insert into a database, and
>>     every few tens of milliseconds flush the buffer, thereby increasing
>>     insertion performance.
>>
>>     However, I don't want to have waiting buffered rows lost at the end of
>>     the program.
>>
>>     I'd like to be able to avoid having to explicitly flush the buffer
>>     before exiting the program, so I'd like to make some kind of
>>     atexit()-alike do it for me.
>>
>>     Any suggestions?
>>
>>     Tony
>>     ____________________
>>       Racket Users list:
>>       http://lists.racket-lang.org/users
>>
>>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.