TypedArrays returned as objects as opposed to arrays...
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...
Which version of Comlink are you using? Do you have a small test case that misbehaves?
Comlink definitely supports copying and transferring TypedArrays. I just added some tests to make sure of that.
@surma, unfortunately I don't have a test case to provide. Like I say it happens not on every run of the worker. More often than not the worker returns the TypedArrays correctly... Other times it returns the TypedArray as an object... Its very peculiar...
I'm using comlink 4.2.0