bun-types 1.1.43 → 1.1.44-canary.20250110T140547
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.d.ts +4 -0
- package/docs/api/ffi.md +14 -0
- package/package.json +1 -1
package/bun.d.ts
CHANGED
package/docs/api/ffi.md
CHANGED
|
@@ -297,6 +297,20 @@ setTimeout(() => {
|
|
|
297
297
|
|
|
298
298
|
When you're done with a JSCallback, you should call `close()` to free the memory.
|
|
299
299
|
|
|
300
|
+
### Experimental thread-safe callbacks
|
|
301
|
+
`JSCallback` has experimental support for thread-safe callbacks. This will be needed if you pass a callback function into a different thread from it's instantiation context. You can enable it with the optional `threadsafe` option flag.
|
|
302
|
+
```ts
|
|
303
|
+
const searchIterator = new JSCallback(
|
|
304
|
+
(ptr, length) => /hello/.test(new CString(ptr, length)),
|
|
305
|
+
{
|
|
306
|
+
returns: "bool",
|
|
307
|
+
args: ["ptr", "usize"],
|
|
308
|
+
threadsafe: true, // Optional. Defaults to `false`
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
```
|
|
312
|
+
Be aware that there are still cases where this does not 100% work.
|
|
313
|
+
|
|
300
314
|
{% callout %}
|
|
301
315
|
|
|
302
316
|
**⚡️ Performance tip** — For a slight performance boost, directly pass `JSCallback.prototype.ptr` instead of the `JSCallback` object:
|
package/package.json
CHANGED