Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update the ref docs to say that cleanupSome is optional.
  • Loading branch information
tjcrowder committed Jun 3, 2020
commit a5bd3fb8d7216d10982aba05640a63387e78a918
9 changes: 5 additions & 4 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ A finalization registry provides a way to request that a *cleanup callback* get
* [The `FinalizationRegistry` Constructor](#the-finalizationregistry-constructor)
* [`FinalizationRegistry.prototype.register`](#finalizationregistryprototyperegister)
* [`FinalizationRegistry.prototype.unregister`](#finalizationregistryprototypeunregister)
* [`FinalizationRegistry.prototype.cleanupSome`](#finalizationregistryprototypecleanupsome)
* [`FinalizationRegistry.prototype.cleanupSome`](#finalizationregistryprototypecleanupsome) *(optional)*

## FinalizationRegistry Overview

Expand Down Expand Up @@ -324,15 +324,15 @@ class Thingy {

### `FinalizationRegistry.prototype.cleanupSome`

Triggers callbacks for an implementation-chosen number of objects in the registry that have been reclaimed but whose callbacks have not yet been called:
This optional method triggers callbacks for an implementation-chosen number of objects in the registry that have been reclaimed but whose callbacks have not yet been called:

```js
registry.cleanupSome(heldValue => {
registry.cleanupSome?.(heldValue => {
// ...
});
```

**NOTE:** Normally, you don't call this function. Leave it to the JavaScript engine's garbage collector to do the cleanup as appropriate. This function primarily exists to support long-running code which doesn't yield to the event loop, which is more likely to come up in WebAssembly than ordinary JavaScript code. Also note that the callback may not be called (for instance, if there are no registry entries whose targets have been reclaimed).
Normally, you don't call this function. Leave it to the JavaScript engine's garbage collector to do the cleanup as appropriate. This function primarily exists to support long-running code which doesn't yield to the event loop, which is more likely to come up in WebAssembly than ordinary JavaScript code. Also note that the callback may not be called (for instance, if there are no registry entries whose targets have been reclaimed).

**Parameters**

Expand All @@ -344,6 +344,7 @@ registry.cleanupSome(heldValue => {

**Notes**

* This method is optional, any given implementation may not have it, so it's best to check that it's there before calling it. One way to do that is to use optional chaining (`?.`) as in the example above, if your environment supports it.
* The number of entries for reclaimed objects that are cleaned up from the registry (calling the cleanup callbacks) is implementation-defined. An implementation might remove just one eligible entry, or all eligible entries, or somewhere in between.


Expand Down