Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

How can I require local file for workers? #102

Closed
zhaoyao91 opened this issue Oct 27, 2017 · 4 comments
Closed

How can I require local file for workers? #102

zhaoyao91 opened this issue Oct 27, 2017 · 4 comments
Labels

Comments

@zhaoyao91
Copy link

Say, how can I broadcast such code in workers?

const f = require('../lib/my_function')
...
@daiyip
Copy link
Contributor

daiyip commented Oct 27, 2017

If you want to just execute a function from a module, you don't need to broadcast in order to use it. Simply do zone.execute('../lib/my_module', 'my_function', [args]);.

Certainly you can do zone.broadcast('f = require("../lib/my_function");, which will set f in global.

@zhaoyao91
Copy link
Author

The function file requires object-hash, which can't be loaded by workers. I don't know why.

@daiyip
Copy link
Contributor

daiyip commented Oct 27, 2017

Please note that napajs by now doesn't support all node modules, since many of Node.js core modules are not supported in Napa.js workers yet. So module that directly or indirectly depends on unsupported Node.js APIs cannot be loaded in workers.

Please see https://github.com/Microsoft/napajs/blob/master/docs/api/node-api.md

@zhaoyao91
Copy link
Author

That's quite a big limitation. Anyway, thanks for help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants