Name
SPVM::Go - Goroutines of The Go Programming Language
Description
The Go class of SPVM has methods to create goroutines and manipulate channels.
Goroutines and channels are features of the Go programming language.
Usage
use Go;
Go->go(method : void () {
my $ch = Go->make;
Go->go([has ch : Go::Channel = $ch] method : void () {
my $ch = $self->{ch};
$ch->write(1);
});
my $ok = 0;
my $value = (int)$ch->read(\$ok);
});
Go->gosched;
Class Methods
go
static method go : void ($task : Callback);
Creates a goroutine.
make
static method make : Go::Channel ($capacity : int = 0);
Creates a channel(Go::Channel) given the capacity of its buffer $capacity.
new_select
static method new_select : Go::Select ();
Creats a new Go::Select object.
gosched
static method gosched : void ();
Suspends the current goroutine.
The control is transferred to the scheduler.
Exceptions:
This method must be called from the main thread. Otherwise an exception is thrown.
gosched_io_read
static method gosched_io_read : void ($fd : int, $timeout : double = 0);
Suspends the current goroutine for IO reading given the file descriptor $fd and the value of the timeout $timeout.
The control is transferred to the scheduler.
Exceptions:
This method must be called from the main thread. Otherwise an exception is thrown.
$timeout must be greater than 0. Otherwise an exception is thrown.
$timeout must be less than or equal to Fn->INT_MAX. Otherwise an exception is thrown.
If IO timeout occurs, an exception is thrown set eval_error_id
to the basic type ID of the Go::Error::IOTimeout class.
gosched_io_write
static method gosched_io_write : void ($fd : int, $timeout : double = 0);
Suspends the current goroutine for IO writing given the file descriptor $fd and the timeout $timeout.
The control is transferred to the scheduler.
Exceptions:
This method must be called from the main thread. Otherwise an exception is thrown.
$timeout must be greater than 0. Otherwise an exception is thrown.
$timeout must be less than or equal to Fn->INT_MAX. Otherwise an exception is thrown.
If IO timeout occurs, an exception is thrown set eval_error_id
to the basic type ID of the Go::Error::IOTimeout class.
sleep
static method sleep : void ($seconds : double = 0);
Sleeps the seconds $seconds.
Exceptions:
This method must be called from the main thread. Otherwise an exception is thrown.
$seconds must be less than or equal to Fn->INT_MAX. Otherwise an exception is thrown.
Repository
See Also
The Go Programming Language - SPVM::Go is a porting of goroutines.
Coro - SPVM::Go uses coroutines.
Author
Yuki Kimoto kimoto.yuki@gmail.com
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License