Merge pull request #478 from davemckeown/zmq-node

Added type definition for ZeroMQ on Node
This commit is contained in:
Boris Yankov
2013-04-15 06:18:13 -07:00
3 changed files with 222 additions and 0 deletions

View File

@@ -115,6 +115,7 @@ List of Definitions
* [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov))
* [Node.js](http://nodejs.org/) (from TypeScript samples)
* [node_redis](https://github.com/mranney/node_redis) (by [Boris Yankov](https://github.com/borisyankov))
* [node_zeromq](https://github.com/JustinTulloss/zeromq.node) (by [Dave McKeown](https://github.com/davemckeown))
* [node-sqlserver](https://github.com/WindowsAzure/node-sqlserver) (by [Boris Yankov](https://github.com/borisyankov))
* [Numeral.js](https://github.com/adamwdraper/Numeral-js) (by [Vincent Bortone](https://github.com/vbortone/))
* [PhantomJS](http://phantomjs.org) (by [Jed Hunsaker](https://github.com/jedhunsaker))

36
node_zeromq/zmq-tests.ts Normal file
View File

@@ -0,0 +1,36 @@
/// <reference path='zmq.d.ts' />
import zeromq = module('zmq');
var zmq: zeromq;
function test1() {
var sock = zmq.socket('push');
sock.bindSync('tcp://127.0.0.1:3000');
sock.send("some work");
}
function test2() {
var sock = zmq.socket('push');
sock.bindSync('tcp://127.0.0.1:3000');
sock.send(new ArrayBuffer(1000));
}
function test3() {
var sock = zmq.socket('push');
sock.bindSync('tcp://127.0.0.1:3000');
sock.send(['hello', 'world']);
}
function test4() {
var sock = zmq.socket(zmq.types.pull);
sock.bind('tcp://127.0.0.1', err => {
sock.send("some work");
});
}
function test5() {
var sock = zmq.socket(zmq.types.pull, zmq.options.linger);
sock.bind('tcp://127.0.0.1', err => {
sock.send("some work");
});
}

185
node_zeromq/zmq.d.ts vendored Normal file
View File

@@ -0,0 +1,185 @@
// Type definitions for ZeroMQ Node
// Project: https://github.com/JustinTulloss/zeromq.node
// Definitions by: Dave McKeown <http://github.com/davemckeown>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare interface EventEmitter {};
declare module 'zmq' {
interface SocketTypes {
pub: number;
xpub: number;
sub: number;
xsub: number;
req: number;
xreq: number;
rep: number;
xrep: number;
push: number;
pull: number;
dealer: number;
router: number;
pair: number;
}
interface SocketOptions {
_fd: number;
_ioevents: number;
_receiveMore: number;
_subscribe: number;
_unsubscribe: number;
affinity: number;
backlog: number;
hwm: number;
identity: number;
linger: number;
mcast_loop: number;
rate: number;
rcvbuf: number;
last_endpoint: number;
reconnect_ivl: number;
recovery_ivl: number;
sndbuf: number;
swap: number;
}
interface Socket extends EventEmitter {
/**
* Set `opt` to `val`.
*
* @param opt Option
* @param val Value
*/
setsocketopt(opt: number, val: any): Socket;
/**
* Set `opt` to `val`.
*
* @param opt Option
* @param val Value
*/
setsocketopt(opt: string, val: any): Socket;
/**
* Get socket `opt`.
*
* @param opt Option number
*/
getsocketopt(opt: number): any;
/**
* Get socket `opt`.
*
* @param opt Option string
*/
getsocketopt(opt: string): any;
/**
* Async bind.
*
* Emits the "bind" event.
*
* @param addr Socket address
* @param cb Bind callback
*/
bind(addr: string, callback: (error: string) => void ): Socket;
/**
* Sync bind.
*
* @param addr Socket address
*/
bindSync(addr: string): Socket;
/**
* Connect to `addr`.
*
* @param addr Connection address
*/
connect(addr: string): Socket;
/**
* Disconnect from `addr`.
*
* @param addr The address
*/
disconnect(addr: string): Socket;
/**
* Subscribe with the given `filter`.
*
* @param filter The filter
*/
subscribe(filter: string): Socket;
/**
* Unsubscribe with the given `filter`.
*
* @param filter The filter
*/
unsubscribe(filter: string): Socket;
/**
* Send the given `msg`.
*
* @param msg The message
* @param flags Message flags
*/
send(msg: string, flags?: number): Socket;
/**
* Send the given `msg`.
*
* @param msg The message
* @param flags Message flags
*/
send(msg: ArrayBuffer, flags?: number): Socket;
/**
* Send the given `msg`.
*
* @param msg The message
* @param flags Message flags
*/
send(msg: Array, flags?: number): Socket;
/**
* Close the socket.
*
*/
close(): Socket;
// Socket Options
_fd: any;
_ioevents: any;
_receiveMore: any;
_subscribe: any;
_unsubscribe: any;
affinity: any;
backlog(): any;
hwm: any;
identity: any;
linger: any;
mcast_loop: any;
rate: any;
rcvbuf: any;
last_endpoint: any;
reconnect_ivl: any;
recovery_ivl: any;
sndbuf: any;
swap: any;
}
export var version: string;
export var types: SocketTypes;
export var options: SocketOptions;
function socket(type: string, options?: any): Socket;
function socket(type: number, options?: any): Socket;
function createSocket(type: string, options?: any): Socket;
}