superfaceai / one-sdk-js

1️⃣ One Node.js SDK for all the APIs you want to integrate with
https://superface.ai
MIT License
47 stars 3 forks source link

[BUG] Comlink foreach changes Buffer variables #215

Closed janhalama closed 2 years ago

janhalama commented 2 years ago

Expected Behavior

When iterating through list of items that contain Buffer variable Comlink foreach should not change Buffer variable and Buffer.isBuffer(item.buffer) should return true.

Current Behavior

Buffer variable in the first item is preserved, but all subsequent items have Buffer variable changed and Buffer.isBuffer(item.buffer) returns false.

Possible Solution

Do not merge item variables when iterating through the list.

Steps to Reproduce

Live example: https://github.com/janhalama/one-sdk-foreach-bug-demo

jnv commented 2 years ago

Current workaround is to pass the source array and index into the operation:

call foreach(index of Array(SOURCE_ARRAY.length).fill().map((_, i) => i)) OPERATION(SOURCE_ARRAY = SOURCE_ARRAY, index = index)

Related: #214