Can someone give me a little program design advice please?
Gary Willoughby
dev at kalekold.net
Sun Jun 16 08:27:27 PDT 2013
I'm writing a little program in D to perform some database
operations and have a small question about design.
Part of my program watches a log file for changes and this
involves code which is wrapped up in a class. So the usage is
something like this:
auto fileWatcher = new FileWatcher(fileName);
fileWatcher.onChange(delegate);
fileWatcher.start();
Once the start method is called a loop is entered within the
class and the file is watched. Changes are handle through calling
the registered delegate. The loop uses different watch methods
for different platforms.
What i need to be able to do is to stop the current watch and
change the watched file.
Because this is in an infinite loop, i can't check externally
i.e. outside of the class, if i need to break from the loop
simply because control never returns to the caller of the start()
method.
Am i missing something simple here? Any advice is welcome. I
thought about threading and message passing but that's maybe
overkill for something as simple as this?
I've also put this question on stackoverflow here
http://stackoverflow.com/questions/17134809/how-to-check-global-events-inside-an-infinite-loop-within-a-class
More information about the Digitalmars-d-learn
mailing list