flowtype

package
v0.0.0-...-b06c216 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DispatchVersion = 4

Variables

View Source
var DefaultRegistry = NewRegistry()
View Source
var GenericDispatch = &DispatchTable{
	Version: DispatchVersion,
	ChanRecver: func(c interface{}) RecvFunc {
		ch := reflect.ValueOf(c)
		if (ch.Type().ChanDir() & reflect.RecvDir) == 0 {
			panic("invalid chan direction")
		}
		return func(cancel <-chan struct{}, block bool) (interface{}, bool) {
			if !block {
				if val, ok := ch.TryRecv(); ok {
					return val.Interface(), true
				}
				return nil, false
			}
			if cancel == nil {
				if val, ok := ch.Recv(); ok {
					return val.Interface(), true
				}
				return nil, false
			}

			idx, val, ok := reflect.Select([]reflect.SelectCase{
				{
					Dir:  reflect.SelectRecv,
					Chan: ch,
				},
				{
					Dir:  reflect.SelectRecv,
					Chan: reflect.ValueOf(cancel),
				},
			})
			if idx == 0 && ok {
				return val.Interface(), true
			}
			return nil, false
		}
	},
	ChanSender: func(c interface{}) SendFunc {
		ch := reflect.ValueOf(c)
		if (ch.Type().ChanDir() & reflect.SendDir) == 0 {
			panic("invalid chan direction")
		}
		nilElem := reflect.Zero(ch.Type().Elem())
		return func(v interface{}, cancel <-chan struct{}, block bool) bool {
			el := nilElem
			if v != nil {
				el = reflect.ValueOf(v)
			}
			if !block {
				return ch.TrySend(el)
			}
			if cancel == nil {
				ch.Send(el)
				return true
			}

			idx, _, _ := reflect.Select([]reflect.SelectCase{
				{
					Dir:  reflect.SelectSend,
					Chan: ch,
					Send: el,
				},
				{
					Dir:  reflect.SelectRecv,
					Chan: reflect.ValueOf(cancel),
				},
			})
			return idx == 0
		}
	},
	FuncCaller: func(f interface{}) CallFunc {
		fn := reflect.ValueOf(f)

		t := fn.Type()
		if t.Kind() != reflect.Func {
			panic("invalid function")
		}

		nilArgs := make([]reflect.Value, t.NumIn())
		for i := range nilArgs {
			nilArgs[i] = reflect.Zero(t.In(i))
		}

		return func(in, out []interface{}) []interface{} {
			var buf [4]reflect.Value
			args := buf[:0]
			for i, v := range in {
				if v == nil {
					args = append(args, nilArgs[i])
				} else {
					args = append(args, reflect.ValueOf(v))
				}
			}

			ret := fn.Call(args)

			if len(ret) == 0 {
				return nil
			}
			if cap(out)-len(out) < len(ret) {
				out = make([]interface{}, 0, len(ret))
			}
			for _, r := range ret {
				out = append(out, r.Interface())
			}
			return out
		}
	},
}

Functions

func As

func As(base, target interface{}) bool

func MustRegisterDispatch

func MustRegisterDispatch(t reflect.Type, i *DispatchTable)

func RegisterDispatch

func RegisterDispatch(t reflect.Type, i *DispatchTable) error

Types

type AnyMessage

type AnyMessage interface{}

AnyMessage for bypassing type convert restrictions, can be connected to and connected by any node.

type CallFunc

type CallFunc func(arg, buf []interface{}) []interface{}

func FuncCaller

func FuncCaller(fn interface{}) CallFunc

type DispatchTable

type DispatchTable struct {
	Version    int
	ChanSender func(ch interface{}) SendFunc
	ChanRecver func(ch interface{}) RecvFunc
	FuncCaller func(fn interface{}) CallFunc
}

type RecvFunc

type RecvFunc func(cancel <-chan struct{}, block bool) (interface{}, bool)

func ChanRecver

func ChanRecver(ch interface{}) RecvFunc

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func (*Registry) GetDispatchTable

func (r *Registry) GetDispatchTable(t reflect.Type) *DispatchTable

func (*Registry) RegisterDispatch

func (r *Registry) RegisterDispatch(t reflect.Type, i *DispatchTable) error

type SendFunc

type SendFunc func(val interface{}, cancel <-chan struct{}, block bool) bool

func ChanSender

func ChanSender(ch interface{}) SendFunc

Directories

Path Synopsis
Code generated by github.com/brian14708/go-flow/flowtype/codegen.
Code generated by github.com/brian14708/go-flow/flowtype/codegen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL