Cú pháp
RealSignal.Once(signal: RealSignal, callback: (....any) -> ()): RealSignalConnectionĐối số
| Tên | Kiểu | Mô tả |
|---|---|---|
signal | RealSignal | Signal object returned by Signal.new. |
callback | (....any) -> () | Function called at most once for this connection. |
Giá trị trả về
| Tên | Kiểu | Mô tả |
|---|---|---|
connection | RealSignalConnection | Connection object with Disconnect. |
Mô tả
Connects a callback that is disconnected before its first callback invocation. The callback receives the arguments passed to Fire.
Goi voi 2 parameter: signal, callback. Bang arguments giai thich gia tri nao bat buoc va gia tri nao chi tinh chinh hanh vi.
Tra ve connection (RealSignalConnection). Dung bang returns de tach gia tri thanh cong, ket qua nil va loi co the xu ly.
Ví dụ
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")Kiểu
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.