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.

gosched_io_read

static method gosched_io_read : void ($fd : int, $timeout_ref : double[] = undef);

Suspends the current goroutine for IO reading given the file descriptor $fd and the value of the timeout reference $timeout_ref.

The control is transferred to the scheduler.

The value of $timeout_ref is updated by the rest timeout. If it is less than 0, timeout has occured.

gosched_io_write

static method gosched_io_write : void ($fd : int, $timeout_ref : double[] = undef);

Suspends the current goroutine for IO writing given the file descriptor $fd and the value of the timeout reference $timeout_ref.

The control is transferred to the scheduler.

The value of $timeout_ref is updated by the rest timeout. If it is less than 0, timeout has occured.

sleep

static method sleep : void ($seconds : double = 0);

Sleeps the seconds $seconds.

Repository

SPVM::Go - Github

See Also

Author

Yuki Kimoto kimoto.yuki@gmail.com

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License