andywer/threads.js

Should we support passing functions to workers?

开放

#145 创建于 2019年8月8日

 (25 条评论) (8 个反应) (0 位负责人)TypeScript (173 个派生)github user discovery
discussionhelp wanted

仓库指标

星标
 (3,531 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

In v0.x we built the library around the idea of passing functions to the worker that would be serialized, passed as a message, deserialized and then executed in the worker.

This approach has some subtle, yet strong limitations, though. That's why v1.0 does not support passing functions anymore, in order to prevent people from running into those not-always-obvious issues.

Maybe there are use cases where one really needs to be able to pass functions to workers. Then we need to make sure, though, that the user is aware of the passed function's limitations:

  • Cannot access any variable declared outside the functions scope
  • Cannot import or require() other modules in the function (at least not in the browser when bundling)

In response to #141, #144.

贡献者指南