Looking to trigger the end of a loop by the creation of a file.

24 views
Skip to first unread message

Don Green

unread,
Oct 2, 2021, 7:25:01 PM10/2/21
to Racket Users
Looking to trigger the end of a loop by the creation of a file.
Is this possible? Is this advisable?
Currently using:
a 'for' loop with
a 'for' loop guard expression to test for the existence of a file.
Tried file-exists? but that does not seem appropriate.
Tried using Racket function: filesystem-change-evt but that did not seem appropriate.
Is it possible to trigger an end condition on a 'for' loop by the creation of a file?
I suspect my problem is that it takes a significant amount of time for the operating system to register the creation of a file.
So maybe the best that can be done is to use file-exists? as it works but there a many loops of the 'for' loop before the end condition takes effect.
Any comments?

Sorawee Porncharoenwase

unread,
Oct 2, 2021, 7:39:13 PM10/2/21
to Don Green, Racket Users
What do you mean by "Tried using Racket function: filesystem-change-evt but that did not seem appropriate."? What's inappropriate about it?

My first thought is to initialize a variable with `#f`. Spawn a thread before the loop that uses `filesystem-change-evt` so that when the event that you are interested in occurs, mutate the variable to `#t`. In the loop, break from the loop when the variable is `#t`.

I guess you can also poll `file-exists?` yourself in the thread, with some `sleep` between each polling.


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/adaf4e50-7430-4d2e-923a-5a0cdff24ebfn%40googlegroups.com.

George Neuner

unread,
Oct 2, 2021, 10:49:56 PM10/2/21
to racket users
> Any comments? --

Is the loop doing something else while it waits?  If not, you might as
well use  filesystem-change-evt.

A polling loop /may/ respond faster than waiting on an event, but at the
level of user applications that is /not/ guaranteed.  Is there some
reason you (think you) need to respond very quickly when the file is
created?

George
Reply all
Reply to author
Forward
0 new messages