github.com/nevalang/neva@v0.23.1-0.20240507185603-7696a9bb8dda/internal/runtime/funcs/new.go (about)

     1  package funcs
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/nevalang/neva/internal/runtime"
     7  )
     8  
     9  type new struct{}
    10  
    11  func (c new) Create(io runtime.FuncIO, msg runtime.Msg) (func(ctx context.Context), error) {
    12  	outport, err := io.Out.Port("msg")
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  
    17  	return func(ctx context.Context) {
    18  		for {
    19  			select {
    20  			case <-ctx.Done():
    21  				return
    22  			case outport <- msg:
    23  			}
    24  		}
    25  	}, nil
    26  }