eventloop

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventLoop

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

func NewEventLoop

func NewEventLoop(opts ...Option) *EventLoop

func (*EventLoop) ClearInterval

func (loop *EventLoop) ClearInterval(i *Interval)

ClearInterval 取消了 SetInterval 返回的 Interval ClearInterval 在事件循环内部或外部调用都是安全的

func (*EventLoop) ClearTimeout

func (loop *EventLoop) ClearTimeout(t *Timer)

ClearTimeout 取消由 SetTimeout 返回的,还没有运行的定时器 ClearTimeout 在事件循环内部或外部调用都是安全的

func (*EventLoop) Run

func (loop *EventLoop) Run(fn func(*goscript.Runtime))

Run 调用指定的函数,启动事件循环并等待,直到没有更多的延迟任务需要运行,之后停止循环并返回 传递给该函数的 Runtime 实例以及由其派生的任何值都不能在该函数之外使用 当事件循环已经运行时,不要使用这个函数,请使用 RunOnLoop() 代替 如果事件循环已经开始,调用它将产生 panic

func (*EventLoop) RunOnLoop

func (loop *EventLoop) RunOnLoop(fn func(*goscript.Runtime))

RunOnLoop 将在循环的上下文中尽快运行指定的函数 运行的顺序被保留(即函数将按照调用 RunOnLoop() 的相同顺序被调用) 传递给函数的 Runtime 实例以及从它派生出来的任何值都不能在函数之外使用,在循环内部或外部调用都是安全的

func (*EventLoop) SetInterval

func (loop *EventLoop) SetInterval(fn func(*goscript.Runtime), timeout time.Duration) *Interval

SetInterval 在每个指定的超时时间段后,在事件循环的上下文中重复运行指定的函数 SetInterval 返回一个 Interval,可以传递给 ClearInterval 传递给该函数的 Runtime 实例以及由它派生的任何值都不能在该函数之外使用 SetInterval 在事件循环内部或外部调用都是安全的

func (*EventLoop) SetTimeout

func (loop *EventLoop) SetTimeout(fn func(*goscript.Runtime), timeout time.Duration) *Timer

SetTimeout 在指定的超时周期触发后,在事件循环的上下文中运行指定的函数 SetTimeout 返回一个 Timer,可以传递给 ClearTimeoutSetTimeout 传递给函数的 Runtime 实例和任何由它派生的值都不能在函数之外使用 SetTimeout 在事件循环内部或外部调用都是安全的

func (*EventLoop) Start

func (loop *EventLoop) Start()

Start 在后台启动事件循环,循环将持续运行,直到调用 Stop() 如果事件循环已经开始,调用它将产生 panic

func (*EventLoop) Stop

func (loop *EventLoop) Stop()

Stop 停止用 Start() 启动的循环。在这个函数返回后,循环内将不再有任何工作被执行 在这之后可以再次调用 Start() 或 Run() 来恢复执行 注意,它不会取消活动超时,不允许同时运行 Start() 和 Stop() 在一个已经停止的循环上或在循环内部调用 Stop() 会挂起

type Interval

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

type Option

type Option func(*EventLoop)

func EnableConsole

func EnableConsole(enableConsole bool) Option

EnableConsole 控制 console 模块是否被加载到事件循环所使用的 Runtime 中 默认情况下,事件循环在创建时加载了 console 模块,将 EnableConsole(false) 传递给 NewEventLoop 可以禁止这种行为

func WithRegistry

func WithRegistry(registry *require.Registry) Option

type Timer

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

Jump to

Keyboard shortcuts

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