RealSignal

RealSignal.Connect

Connects a callback to a RealSignal and returns a RealSignalConnection.

语法

RealSignal.Connect(signal: RealSignal, callback: (....any) -> ()): RealSignalConnection

参数

名称类型描述
signalRealSignalSignal object returned by Signal.new.
callback(....any) -> ()Function called whenever the signal is fired while the connection remains connected.

返回值

名称类型描述
connectionRealSignalConnectionConnection object with Disconnect.

说明

Connects a callback to a RealSignal and returns a RealSignalConnection. The callback receives the arguments passed to Fire.

使用 2 个参数调用: signal, callback。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 connection (RealSignalConnection)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

Connect a callback and disconnect it when it is no longer needed.

local signal = Signal.new()

local connection = signal:Connect(function(value)
    print(value)
end)

signal:Fire(1)
connection:Disconnect()

类型

RealSignal

Signal object returned by Signal.new.

Connect (callback: (...any) -> ()) -> RealSignalConnection Adds a callback that runs when Fire is called.Once (callback: (...any) -> ()) -> RealSignalConnection Adds a callback that is disconnected before its first callback invocation.Wait () -> ...any Yields until Fire resumes the waiter with the fired values.Fire (...values: any) -> () Runs connected callbacks and resumes waiters with the provided values.

RealSignalConnection

Connection object returned by RealSignal.Connect and RealSignal.Once.

Disconnect () -> () Disconnects the connection.