Name
SPVM::Go::Channel - Golang Compatible Channel
Description
Go::Channel class of SPVM has methods to manipulate channels.
Usage
use Go;
# A non-buffered channel
my $channel = Go->make;
# A buffered channel
my $channel = Go->make(3);
# Read channel
my $ok = 0;
my $value = $channel->read(\$ok);
# Write channel
$channel->write($value);
Instance Methods
read
method read : object ($ok_ref : int*);
Reads a value from the channel. If the value is red from a closed channl, undef is returned.
If the channel is closed and any written values do not exist, the value referred by $ok_ref is set to 0, otherwise it is set to 1.
write
method write : void ($value : object);
Writes a value to the channel. If the buffer is full, this method blocks until the value is red or there is free buffer space.
Exceptions:
If this channel is closed, an exception is thrown.
close
method close : void ();
Closes the channel. A closed channel cannot be writen.
Exceptions:
If this channel is already closed, an exception is thrown.
cap
method cap : int ();
Gets the buffer capacity of the channel.
len
method len : int ();
Gets the length of the values in the buffer.
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License