RealSignal

RealSignal.Connect

Connects a callback to a RealSignal and returns a RealSignalConnection.

ไวยากรณ์

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

Arguments

ชื่อชนิดคำอธิบาย
signalRealSignalSignal object returned by Signal.new.
callback(....any) -> ()Function called whenever the signal is fired while the connection remains connected.

Returns

ชื่อชนิดคำอธิบาย
connectionRealSignalConnectionConnection object with Disconnect.

คำอธิบาย

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

เรียกด้วย parameter 2 ค่า: signal, callback ตาราง arguments อธิบายค่าที่จำเป็นและค่าที่ปรับพฤติกรรม

ส่งคืน connection (RealSignalConnection) ใช้ตาราง returns เพื่อแยกค่าที่สำเร็จ ผลลัพธ์ nil และ error ที่จัดการต่อได้

ตัวอย่าง

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()

Types

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.