Sign in to PrePAN

Interact::Later Delay some tasks for later by dumping their data to disk



use Interact::Later;

my $delayer = Interact::Later->new(
  cache_path => 'path/to/cache',
  file_extension => '.dmp'


# Later...
# Do it until there are no more files...

# Finally


Can be used, for example, when you receive lots of POST requests that you don't want to proceed right now to save database load.

This module will fastly store the data content on disk (with Storable) without the need to use a database or a job queue. Assuming that Perl is fast at writing files to disk, we can hope good results. This is an experiment...


I think a better module name would be one where the words "file" and "queue" occur. In fact, a search on CPAN shows that there are already similar modules, for example or . Maybe these already do what you want to do with your module?

Looking at the code it seems that you work with the stat() function to get the oldest file. Unfortunately the time fields stat() return don't have sub-second accuracy --- this means that the oldest file the module will return is not really the oldest one. Theoretically some operating systems (linux?) with some filesystems may provide sub-second information, but then some perl module (maybe there's a CPAN module?) has to provide this information.
About the name, I found no good idea and it should have been `Will::Choose::Later`. Will surely change soon.

About the existing modules, I searched before and saw at least `File::Queue`, but you know, I evaluated it and felt reluctant using a 15 years old module with no tests.
Maybe I should study the implementation and borrow some good ideas.

About the `stat` thing, it's very important indeed, since the reason I started this is about queueing fast (100 times a second is fine).

Thanks for all the comments!
Time::HiRes has a subsecond stat function, though it only works if the underlying file system supports timestamps of that resolution.

Of course you could use Time::HiRes to prepend a subsecond timestamp to your filenames (don't forget to pad the timestamp with leading zeros). That would enable you to order the files by timestamp with a simple sort - and if you're just after the oldest file you can save yourself some CPU cycles by using the minstr from List::Util.

Please sign up to post a review.