Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map.String is not clonable #8

Open
pbiggar opened this issue Jul 30, 2021 · 2 comments
Open

Map.String is not clonable #8

pbiggar opened this issue Jul 30, 2021 · 2 comments

Comments

@pbiggar
Copy link
Member

pbiggar commented Jul 30, 2021

When attempting to send a Map.String.t to a web worker, I got an error:

Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': function caml_compare(_a, _b) {
  while(true) {
    var b = _b;
    var a = _a;
    if (a === b) {
      return...<omitted>...
} could not be cloned.

This was not the case in 0.0.7. I think the difference is that StrDict in 0.0.7 was a Belt.MapString, which had a built-in comparator.

@pbiggar
Copy link
Member Author

pbiggar commented Aug 2, 2021

I investigated this more. The situation is that Belt.Map has a cmp field in the generated object, which holds a function. That function (like all functions) can't be serialized using the cloning algorithm used by web workers.

I tried to fix this in darklang/tablecloth#229. This PR separated Set.String.t from Set.t, making the former a Belt.Set.String, which has a built-in comparator and does not suffer from the cmp field issue.

Ultimately, this became very annoying very fast. It had a number of issues:

  • all the Set functions needed to be copied to Set.String and Set.Int (I couldn't find any way to reuse Belt.Set or its functions, and so needed to make a whole new set of functionality)
  • the interface would no longer be the same as the native version of Set.String
  • My code needs to change to use Tablecloth.Map.String.* everywhere, versus at the moment you can do Tablcloth.Map.* for nearly all functions. These were hundreds of changes
  • Any time I wanted to create a Map that wasn't of Int or Strings, that initial (unclonable) problem continued to exist.

@pbiggar
Copy link
Member Author

pbiggar commented Oct 11, 2022

This will be solved by #6, leaving open to confirm.

@pbiggar pbiggar transferred this issue from darklang/tablecloth Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant