sudu

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 3 Imported by: 0

README

GoDoc

待重构

ConditionGroup

条件依赖模型, 有点类似于pub/sub模型,但对于条件而言,只有满足与不满足。 条件满足后,所有对该条件的引用全部不会阻塞,且一定成功,不用像pub/sub模型中先行订阅。

ConditionGroup

Sudu

Sudu,用于将存在条件依赖的并发调用,利用cache机制将依赖解开,变成并发调用, 核心需要处理的,则是依赖条件值的legacy问题。 使用legacy的值抢先进行预测,当依赖的条件由legacy状态转变为unlegacy时, 对应抢先预测的任务需要检查自身刚做完的结果是否有必要重做, 自身是否也受到unlegacy影响,也应当转变为unlegacy状态。

Sudu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCacheBucket

func GetCacheBucket(ns string) *gcache.Cache

Types

type Cache

type Cache struct {
	Cache *gcache.Cache
	Key   string
}

func NewCache

func NewCache(ns, key string) *Cache

func (*Cache) Delete

func (c *Cache) Delete()

func (*Cache) Get

func (c *Cache) Get() []interface{}

func (*Cache) Set

func (c *Cache) Set(nvs []interface{})

type CancelMessage

type CancelMessage struct {
	Message interface{}
}

type ConditionGroup

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

条件依赖模型 有点类似于pub/sub模型 但对于条件而言,只有满足与不满足 条件满足后,所有对该条件的引用全部不会阻塞,且一定成功,不用像pub/sub模型中先行订阅

func NewConditionGroup

func NewConditionGroup() *ConditionGroup

func (*ConditionGroup) Cancel

func (cg *ConditionGroup) Cancel(nvs ...interface{})

name, msg, [name, msg, ...]

func (*ConditionGroup) Inspect

func (cg *ConditionGroup) Inspect(name interface{}) (interface{}, *CancelMessage, bool)

read from raw map

func (*ConditionGroup) Require

func (cg *ConditionGroup) Require(name interface{}) interface{}

got or panic

func (*ConditionGroup) Satisfy

func (cg *ConditionGroup) Satisfy(nvs ...interface{})

name, value, [name, value, ...]

func (*ConditionGroup) Want

func (cg *ConditionGroup) Want(name interface{}) (interface{}, *CancelMessage)

raw map first, otherwise waiting for Satisfy()

type ConditionTask

type ConditionTask struct {
	ConditionGroup
	TaskGroup
}

快速组合 sudu的一种简单的降级使用方式 不涉及条件的legacy状态变更问题 所有条件只区分有和没有 可以尽最大努力在满足条件的前提下进行任务并发

func NewConditionTask

func NewConditionTask() *ConditionTask

type Sudu

type Sudu struct {
	ConditionGroup

	Tasks   int
	Running int
	WaitAll bool
	// contains filtered or unexported fields
}

Sudu,用于将存在条件依赖的并发调用,利用cache机制将依赖解开,变成并发调用 核心需要处理的,则是依赖条件值的legacy问题 使用legacy的值抢先进行预测,当依赖的条件由legacy状态转变为unlegacy时 对应抢先预测的任务需要检查自身刚做完的结果是否有必要重做 自身是否也受到unlegacy影响,也应当转变为unlegacy状态

func NewSudu

func NewSudu(c *Cache) *Sudu

func (*Sudu) Conditions

func (sd *Sudu) Conditions() []interface{}

func (*Sudu) Go

func (sd *Sudu) Go(fxs ...func(*ConditionGroup))

func (*Sudu) SatisfyLegacy

func (sd *Sudu) SatisfyLegacy(nvs ...interface{})

name, value, [name, value, ...]

func (*Sudu) Wait

func (sd *Sudu) Wait() error

type TaskGroup

type TaskGroup struct {
	Tasks   int
	Running int
	WaitAll bool
	// contains filtered or unexported fields
}

一个waitgroup的高级封装

func NewTaskGroup

func NewTaskGroup() *TaskGroup

func (*TaskGroup) Go

func (tg *TaskGroup) Go(fxs ...func())

if fx panic(),the Wait will be unblock immediately by default (controled by WaitAll) if fx first panic(error), the Wait will return the error if fx first panic(anyother), the Wait will panic as the same otherwise, Wait return nil

func (*TaskGroup) Wait

func (tg *TaskGroup) Wait() error

Jump to

Keyboard shortcuts

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