node-ffi-rs
Advanced tools
Comparing version 1.0.64 to 1.0.65
@@ -95,3 +95,7 @@ export const enum DataType { | ||
type ResultWithPromise<T, U extends boolean | undefined = undefined> = U extends true | ||
? Promise<T> | ||
: T; | ||
export type FieldType = | ||
@@ -114,3 +118,3 @@ | DataType | ||
export type FFIParams<T extends FieldType, U extends boolean | undefined = undefined> = { | ||
export type FFIParams<T extends FieldType, U extends boolean | undefined = undefined, RunInNewThread extends boolean | undefined = undefined> = { | ||
library: string; | ||
@@ -123,14 +127,16 @@ funcName: string; | ||
errno?: U | ||
runInNewThread?: RunInNewThread | ||
} | ||
export function load<T extends FieldType, U extends boolean | undefined = undefined>( | ||
params: FFIParams<T, U>, | ||
): ResultWithErrno<FieldTypeToType<T>, U> | ||
export function load<T extends FieldType, U extends boolean | undefined = undefined, RunInNewThread extends boolean | undefined = undefined>( | ||
params: FFIParams<T, U, RunInNewThread>, | ||
): ResultWithPromise<ResultWithErrno<FieldTypeToType<T>, U>, RunInNewThread> | ||
type FuncObj< | ||
T extends FieldType, | ||
U extends boolean | undefined = undefined | ||
> = Record<string, Omit<FFIParams<T, U>, 'paramsValue' | 'funcName'>> | ||
U extends boolean | undefined = undefined, | ||
RunInNewThread extends boolean | undefined = undefined | ||
> = Record<string, Omit<FFIParams<T, U, RunInNewThread>, 'paramsValue' | 'funcName'>> | ||
export function define<T extends FuncObj<FieldType, boolean | undefined>>(funcs: T): { | ||
[K in keyof T]: (...paramsValue: Array<unknown>) => ResultWithErrno<FieldTypeToType<T[K]['retType']>, T[K]['errno']>; | ||
[K in keyof T]: (...paramsValue: Array<unknown>) => ResultWithPromise<ResultWithErrno<FieldTypeToType<T[K]['retType']>, T[K]['errno']>, T[K]['runInNewThread']>; | ||
} |
{ | ||
"name": "node-ffi-rs", | ||
"version": "1.0.64", | ||
"version": "1.0.65", | ||
"main": "index.js", | ||
@@ -42,2 +42,3 @@ "types": "index.d.ts", | ||
"benny": "^3.7.1", | ||
"conventional-changelog-cli": "^4.1.0", | ||
"esno": "^4.0.0", | ||
@@ -58,14 +59,15 @@ "ffi-napi": "^4.0.3", | ||
"universal": "napi universal", | ||
"version": "napi version" | ||
"version": "napi version", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" | ||
}, | ||
"optionalDependencies": { | ||
"@yuuang/ffi-rs-win32-x64-msvc": "1.0.64", | ||
"@yuuang/ffi-rs-darwin-x64": "1.0.64", | ||
"@yuuang/ffi-rs-linux-x64-gnu": "1.0.64", | ||
"@yuuang/ffi-rs-darwin-arm64": "1.0.64", | ||
"@yuuang/ffi-rs-linux-arm64-gnu": "1.0.64", | ||
"@yuuang/ffi-rs-linux-arm64-musl": "1.0.64", | ||
"@yuuang/ffi-rs-win32-ia32-msvc": "1.0.64", | ||
"@yuuang/ffi-rs-linux-x64-musl": "1.0.64" | ||
"@yuuang/ffi-rs-win32-x64-msvc": "1.0.65", | ||
"@yuuang/ffi-rs-darwin-x64": "1.0.65", | ||
"@yuuang/ffi-rs-linux-x64-gnu": "1.0.65", | ||
"@yuuang/ffi-rs-darwin-arm64": "1.0.65", | ||
"@yuuang/ffi-rs-linux-arm64-gnu": "1.0.65", | ||
"@yuuang/ffi-rs-linux-arm64-musl": "1.0.65", | ||
"@yuuang/ffi-rs-win32-ia32-msvc": "1.0.65", | ||
"@yuuang/ffi-rs-linux-x64-musl": "1.0.65" | ||
} | ||
} |
@@ -26,2 +26,3 @@ # ffi-rs | ||
- Provide many ways to handle pointer type directly 🐮 | ||
- Support run ffi task [in a new thread](#runInNewThread) 🤩️ | ||
- Support output [errno](#errno) info 🤔️ | ||
@@ -685,1 +686,23 @@ | ||
``` | ||
## runInNewThread | ||
`ffi-rs` support run ffi task in a new thread without blocking the main thread which is useful for cpu intensive task. | ||
To use the feature, you can pass `runInNewThread` option to load method | ||
```js | ||
const testRunInNewThread = async () => { | ||
// will return a promise but the task will run in a new thread | ||
load({ | ||
library: "libsum", | ||
funcName: "sum", | ||
retType: DataType.I32, | ||
paramsType: [DataType.I32, DataType.I32], | ||
paramsValue: [1, 2], | ||
runInNewThread: true, | ||
}).then(res => { | ||
equal(res, 3) | ||
}) | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35067
450
707
9