GoogleChromeLabs / GoogleChromeLabs/comlink
TypedArrays returned as objects as opposed to arrays...
- Dominant language
- TypeScript
- Stars
- 12.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
Description
Hi! I'm am finding that comlink will sometimes return typed-arrays as objects from my worker. However, the majority of the time comlink returns the typed-arrays as expected...
From my worker I am returning an object that looks like:
```
{
id: 123,
ary: Uint8Array.from([1,2,3,4]),
ary1: Float64Array.from([1.234, 2.234, 3.234])
}
```
When I receive the object back on the main thread sometimes _(not always)_ the object will likk like...
```
{
id: 123,
ary: {0: 1, 1: 2, 2: 3, 3: 4},
ary1: {0: 1.234, 1: 2.234, 2: 3.234}
}
```
I have tried forcing the typed-arrays to be transferrables like so, but this resulted in the same behavior...
```
const ary = Uint8Array.from([1,2,3,4]);
const ary1 = Float64Array.from([1.234, 2.234, 3.234])
{
id: 123,
ary: Comlink.transfer(ary, [ary.buffer]),
ary1: Comlink.transfer(ary1, [ary1.buffer])
}
```
The object is passed to a proxy function. Not sure if that makes a difference or not...
Does comlink have a limitation with transferring type-arrays as part of an object structure like shown above? Obviously, I'm doing something wrong; any help is greatly appreciated...
Contributor guide
Assessment
This issue has not been assessed yet.