Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Retain snapshots for async callbacks #1632

Closed

Conversation

drarmstr
Copy link
Contributor

Summary:
Automatically retains snapshots from useRecoilCallback() for the duration of async callbacks until the promise is resolved. This should help avoid potential user errors without needing to manually remember to retain() and release in a finally clause.

Before:

const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});

After:

const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: D34405832

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Feb 23, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D34405832

@drarmstr drarmstr self-assigned this Feb 23, 2022
@drarmstr drarmstr added the enhancement New feature or request label Feb 23, 2022
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Feb 23, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: D34405832

fbshipit-source-id: cdd76b8d46488d79acc81a47f6cb257d6ed9d246
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D34405832

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Feb 23, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: D34405832

fbshipit-source-id: a82259e3912b72b3c08e95acb57c4a0d06d5ab95
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D34405832

Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Reviewed By: mondaychen

Differential Revision: D34405832

fbshipit-source-id: eecd96f0b581c4eb69f1c347eda18a8a72ce508c
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D34405832

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 17, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: 36ec7585ec95ab6165e5782a126936f3c3e78c66
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 17, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: da076434c923dde6fc31c1920c6260bdefe19986
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 17, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: 50658d90b88a3da10004356c2870cf812164a29c
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 17, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: 7cb310815c669a62623f1819c4bf8841f9c5002a
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 17, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: 7f88517f6d46568ef9cb8cb8811c1742939d5ff2
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Mar 18, 2022
Summary:
Pull Request resolved: facebookexperimental#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Differential Revision: https://www.internalfb.com/diff/D34405832?entry_point=27

fbshipit-source-id: 45b7fd1dbea20f57d7c437061365e3846e0b8651
@drarmstr drarmstr deleted the export-D34405832 branch April 1, 2022 23:34
AlexGuz23 pushed a commit to AlexGuz23/Recoil that referenced this pull request Nov 3, 2022
Summary:
Pull Request resolved: facebookexperimental/Recoil#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Reviewed By: mondaychen

Differential Revision: D34405832

fbshipit-source-id: daddc09a037c3f91b9790464adae7981191a16dd
snipershooter0701 pushed a commit to snipershooter0701/Recoil that referenced this pull request Mar 5, 2023
Summary:
Pull Request resolved: facebookexperimental/Recoil#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Reviewed By: mondaychen

Differential Revision: D34405832

fbshipit-source-id: daddc09a037c3f91b9790464adae7981191a16dd
eagle2722 added a commit to eagle2722/Recoil that referenced this pull request Sep 21, 2024
Summary:
Pull Request resolved: facebookexperimental/Recoil#1632

Automatically retains snapshots from `useRecoilCallback()` for the duration of async callbacks until the promise is resolved.  This should help avoid potential user errors without needing to manually remember to `retain()` and release in a `finally` clause.

Before:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  const release = snapshot.retain();
  try {
    ... await
    ... use snapshot
  } finally {
    release();
  }
});
```

After:
```
const callback = useRecoilCallback(({snapshot}) => async () => {
  ... await
  ... use snapshot
});
```

Manually retaining is still required if trying to persist the the Snapshot beyond the lifetime of the async callback or if it is used in async callbacks not dependent to a returned promise.

Reviewed By: mondaychen

Differential Revision: D34405832

fbshipit-source-id: daddc09a037c3f91b9790464adae7981191a16dd
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants