`node-webworkers` is an implementation of the [Web Workers
API](http://www.whatwg.org/specs/web-workers/current-work/) for
[node.js](http://nodejs.org).
See the design document
[here](http://blog.std.in/2010/07/08/nodejs-webworker-design/).
### Example
#### Master source
var sys = require('sys');
var Worker = require('webworker');
var w = new Worker('foo.js');
w.onmessage = function(e) {
sys.debug('Received mesage: ' + sys.inspect(e));
w.terminate();
};
w.postMessage({ foo : 'bar' });
#### Worker source
onmessage = function(e) {
postMessage({ test : 'this is a test' });
};
onclose = function() {
sys.debug('Worker shuttting down.');
};
### API
Supported API methods are
* `postMessage(e)` in both workers and the parent; messages are in the
parent if this is invoked before the child is fully initialized
* `onmessage(e)` in both workers and the parent
* `onerror(e)`in both workers and the parent
* `terminate()` in the parent
In addition, some nonstandard APIs are provided
* `onclose()` in the worker (allows for graceful shutdown)
* The `postMessage()` method takes an additional optional file descriptor parameter, which
will be sent with the message. This descriptor will be passed to
`onmessage` handlers as an optional `fd` field. Handlers receiving
messages posted without file descriptors will not see an `fd` field. Both
the parent and child can send file descriptors using this mechanism.
* `Worker.onexit(code, signal)` in the master, which is invoked on the
master `Worker` object when the worker process exits.
* The `Worker` constructor takes an additional optional object argument,
`opts`, which is used as a dictionary of options with the following keys
* `args` : A string or array of strings to pass to the executable before the filename to invoke. This can be used to request that the worker start up in debug mode (e.g. `{ 'args' : '--debug-brk' }`). By default this is empty.
* `path` : A string naming the executable to invoke for workers. By default this is the value of `process.execPath` (e.g. `node` or similar).
### Installation
This package can be installed via [npm](http://npmjs.org/) as follows
% npm install webworker
Note that this requires
[node-websocket-client](http://github.com/pgriess/node-websocket-client) v0.9.3
or later. This dependency will be handled automatically by `npm`, but must be
dealt with manually if installing using another procedure.
### Credits
This package contains a static snapshot of Micheil Smith's excellent
[node-websocket-server](http://github.com/miksago/node-websocket-server) with
some fixes applied to handle UNIX sockets.
没有合适的资源?快使用搜索试试~ 我知道了~
node-webworker, NodeJS的WebWorkers实现.zip
共21个文件
js:14个
md:3个
gitignore:1个
需积分: 9 2 下载量 64 浏览量
2019-09-18
20:22:38
上传
评论
收藏 23KB ZIP 举报
温馨提示
node-webworker, NodeJS的WebWorkers实现 node-webworkers 是网络工作者API的一个实现,用于 node.js 。请参见这里的设计文档 。示例主源var sys = require('sys');var Worker = require('web
资源推荐
资源详情
资源评论
收起资源包目录
node-webworker.zip (21个子文件)
node-webworker-master
.gitignore 29B
README.md 3KB
test
workers
simple.js 501B
fd.js 344B
error.js 115B
test-fd.js 737B
test-simple.js 800B
test-error.js 631B
docs
design.md 5KB
examples
prefork
README.md 71B
worker.js 425B
master.js 352B
LICENSE 1KB
package.json 628B
Makefile 312B
lib
ws
connection.js 11KB
manager.js 2KB
ws.js 3KB
webworker.js 9KB
webworker-util.js 5KB
webworker-child.js 5KB
共 21 条
- 1
资源评论
weixin_38743968
- 粉丝: 404
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 人工智能实验四 感知器算法的设计实现
- java小项目多线程多线程 复制文件 冒泡排序 群聊
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功