#this code should block if nothing comes from child 2 and during that time it
#may receive data from child1 that wont be acted upon
while(<$child1>){
try something...will block if nothing comes from child 1
my $line = <$child2>
while(!defined $line){
$line = <$child2>;
do something else
}
}
####
while(1){
print "recving\n";
my $hash = $trader->{venues}->{$venues[0]}->{ticker_tape}->recv;
print "recved\n";
my $parsed = parse_json($hash);
print "\n" x 5;
print "$hash";
print "\n" x 5;
}
####
$self->{venues}->{$i}->{client} = AnyEvent::WebSocket::Client->new;
my $cv = $self->{venues}->{$i}->{client}->connect("wss://api.stockfighter.io/ob/api/ws/$self->{account}/venues/$i/tickertape")->cb(sub{
our $connection = eval { shift->recv };
if($@) {
warn $@;
return;
}
$connection->on(each_message => sub {
my($connection, $message) = @_;
my $decode = parse_json($message->{body});
print "got a message ticker!\n";
$self->{venues}->{$i}->{ticker_tape}->send($message->{body});
});
$connection->on(finish => sub {
# $connection is the same connection object
my($connection) = @_;
$connection->close;
});
});