# `Yex.Subscription`
[🔗](https://github.com/satoren/y_ex/blob/main/lib/subscription.ex#L1)

Provides subscription functionality for monitoring changes in shared types.
This module implements features for observing changes in documents and other shared types,
and receiving notifications when changes occur.

## Features
- Monitor change events in shared types
- Process-level subscription management
- Prevention of automatic resource release
- Simple unsubscribe functionality

## Usage
Subscriptions are typically created by monitoring functions like `Yex.Doc.monitor_update/2`
or `Yex.SharedType.observe/2` and are used to receive change notifications:

    iex> doc = Yex.Doc.new()
    iex> {:ok, ref} = Yex.Doc.monitor_update(doc)
    iex> # Monitor changes...
    iex> Yex.Subscription.unsubscribe(ref) # Unsubscribe from monitoring
    :ok

# `t`

```elixir
@type t() :: %Yex.Subscription{doc: Yex.Doc.t(), reference: reference()}
```

# `register`

Registers a subscription and returns a reference.
This function stores the subscription in the process dictionary to prevent
automatic release by the garbage collector.

## Parameters
  * `sub` - The subscription to register
  * `ref` - Optional reference. If not provided, a new reference will be generated

## Returns
  * The subscription reference

# `unsubscribe`

Unsubscribes from a subscription.
Removes the subscription associated with the given reference from the
process dictionary and cleans up resources.

## Parameters
  * `ref` - The reference of the subscription to unsubscribe

## Returns
  * `:ok` - If unsubscription was successful

---

*Consult [api-reference.md](api-reference.md) for complete listing*
