> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# RealSignal.Connect

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

<div className="real-function-page">
  ```lua theme={null}
  RealSignal.Connect(signal: RealSignal, callback: (....any) -> ()): RealSignalConnection
  ```

  ## 引数

  <ParamField path={"signal"} type={"RealSignal"} required>
    Signal object returned by Signal.new.
  </ParamField>

  <ParamField path={"callback"} type={"(....any) -> ()"} required>
    Function called whenever the signal is fired while the connection remains connected.
  </ParamField>

  ## 戻り値

  <ResponseField name={"connection"} type={"RealSignalConnection"}>
    Connection object with Disconnect.
  </ResponseField>

  ## 型

  ### RealSignal

  Signal object returned by Signal.new.

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

  ### RealSignalConnection

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

  | Name         | Type       | Required | 説明                          |
  | ------------ | ---------- | -------- | --------------------------- |
  | `Disconnect` | `() -> ()` | Yes      | Disconnects the connection. |

  ## 例

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

  ```lua theme={null}
  local signal = Signal.new()

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

  signal:Fire(1)
  connection:Disconnect()
  ```
</div>
