[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Types](https://evolu.dev/docs/api-reference/common/Types) › CallbackWithTeardown

```ts
type CallbackWithTeardown<T> = (value: T) => void | (() => void);
```

Defined in: [packages/common/src/Types.ts:73](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Types.ts#L73)

A function that receives a value and optionally returns a teardown function.

Use for subscriptions or callbacks that need abort-time teardown.

### Subscription teardown

```ts

interface EventSource {
  readonly start: () => void;
  readonly stop: () => void;
}

const events: Array<string> = [];
const source: EventSource = {
  start: () => {
    events.push("started");
  },
  stop: () => {
    events.push("stopped");
  },
};
const subscribe: CallbackWithTeardown<EventSource> = (source) => {
  source.start();
  return source.stop;
};
const teardown = subscribe(source);
if (teardown) teardown();

assertEqual(events, ["started", "stopped"]);
```