I'm having trouble finding an example of how to create and write to a file using a POE Wheel or whatever async process. I want to be able to write large files in a non blocking way. I'm looking for examples, but don't know where to start.
Asked
Active
Viewed 374 times
1
-
There is very good documentation available: http://search.cpan.org/~rcaputo/POE-1.354/lib/POE/Wheel/ReadWrite.pm – Matthias May 03 '13 at 22:56
-
Thanks. I checked that out and ended up figuring out how to do it. I posted my resulting code on the thread. The examples in the doc you linked were good, but not that clear for fileio. There was an example that referenced reading from STDIN and that's the one that ended up helping me though. – dudeman May 06 '13 at 18:24
1 Answers
1
So, I didn't really find a straight forward example for file io. But, I managed to figure out this working code from the examples I did find. I think it's what I want. I'm adding it here so if anyone has any comments it might help me or other improve it. Or, if someone else is looking for an example they can see this one.
$self->{FILEIO_SESSION} = POE::Session->create(
inline_states => {
_start => sub {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
$kernel->alias_set($fileio_uuid);
$heap->{wheels}->{$fileio_uuid} = POE::Wheel::ReadWrite->new(
InputHandle => $infile_fh ,
OutputHandle => $outfile_fh,
Driver => POE::Driver::SysRW->new(),
Filter => POE::Filter::Line->new(),
InputEvent => 'readLineEvent',
ErrorEvent => 'errorEvent'
);
},
_stop => sub {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
print "Removing fileio session\n";
$kernel->alias_remove($fileio_uuid);
},
readLineEvent => sub {
my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ];
print "read a line...writing to file...\n";
$heap->{wheels}->{$fileio_uuid}->put($input);
},
errorEvent => sub {
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
print "Everything either went to hell or we got to the end. Shutting down...\n";
delete $heap->{wheels}->{$fileio_uuid};
$kernel->yield("_stop");
}
}
);

dudeman
- 503
- 3
- 11