# `Electric.Shapes.Consumer.PendingTxn`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/shapes/consumer/pending_txn.ex#L1)

Tracks metadata for an in-progress transaction during direct fragment-to-storage streaming of
changes.

When a consumer streams transaction fragments directly to storage (for shapes
without subquery dependencies), this struct tracks the transaction metadata
until commit is received.

This is an antipod module to Electric.Replication.TransactionBuilder. This module only tracks
metadata related to the current transaction for which txn fragments are processed as the
fragments themselves are written to strorage and are discarded from memory immediately, while
the TransactionBuilder module accumulates all changes in memory and returns a complete
transaction after seeing a Commit.

# `t`

```elixir
@type t() :: %Electric.Shapes.Consumer.PendingTxn{
  consider_flushed?: boolean(),
  num_changes: non_neg_integer(),
  storage_duration: term(),
  total_bytes: non_neg_integer(),
  xid: pos_integer()
}
```

# `consider_flushed`

# `new`

```elixir
@spec new(pos_integer()) :: t()
```

Create a new pending transaction tracker.

# `update_with_changes`

```elixir
@spec update_with_changes(
  t(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) :: t()
```

Update the pending transaction with changes that were written to storage.

---

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