Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 11071f3

Browse files
author
Daniel Ehrenberg
authored
Merge pull request #206 from tjcrowder/feature/cleanupsome-doc-update
Update the ref docs to say that `cleanupSome` is optional.
2 parents 16fc317 + 684c7d4 commit 11071f3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

reference.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,17 @@ class Thingy {
324324

325325
### `FinalizationRegistry.prototype.cleanupSome`
326326

327-
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:
327+
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:
328328

329329
```js
330330
registry.cleanupSome?.(heldValue => {
331331
// ...
332332
});
333333
```
334334
335-
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).
335+
This method is optional, any given implementation may not have it. It's expected not to be present on web browsers, at least not initially; see [HTML issue #5446](https://github.com/whatwg/html/issues/5446) for details. Since the method is optional, you need to check that it's there before calling it. One way to do that is to use [optional chaining](https://github.com/tc39/proposal-optional-chaining) (`?.`) as in the example above.
336+
337+
Normally, you don't call this function. Leave it to the JavaScript engine's garbage collector to do the callbacks 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).
336338
337339
**Parameters**
338340
@@ -344,7 +346,6 @@ Normally, you don't call this function. Leave it to the JavaScript engine's garb
344346
345347
**Notes**
346348
347-
* 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.
348349
* 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.
349350
350351

0 commit comments

Comments
 (0)