---
title: "storeWhileEntityActive(_:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/cancellable/storewhileentityactive(_:)"
---

# storeWhileEntityActive(_:)

Retains the Cancellable as long as the entity is active (see Entity.isActive). If the entity is deactivated, the Cancellable is released.

## Declaration

```swift
@MainActor @preconcurrency func storeWhileEntityActive(_ entity: Entity)
```

## Discussion

Discussion This method does nothing if the entity is already inactive. Internally, this method stores an AnyCancellable in a transient component of the entity. The component is removed when the deactivate event for this entity is received.
