语法
RealSignal.Once(signal: RealSignal, callback: (....any) -> ()): RealSignalConnection参数
| 名称 | 类型 | 描述 |
|---|---|---|
signal | RealSignal | Signal object returned by Signal.new. |
callback | (....any) -> () | Function called at most once for this connection. |
返回值
| 名称 | 类型 | 描述 |
|---|---|---|
connection | RealSignalConnection | Connection object with Disconnect. |
说明
Connects a callback that is disconnected before its first callback invocation. The callback receives the arguments passed to Fire.
使用 2 个参数调用: signal, callback。参数表会说明哪些值必填,哪些值只用于细化行为。
返回 connection (RealSignalConnection)。使用返回表区分成功值、nil 结果和可恢复错误。
示例
Connect a callback that runs at most once.
local signal = Signal.new()
signal:Once(function(value)
print(value)
end)
signal:Fire("first")
signal:Fire("second")类型
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.