Add typings for nanomsg

This commit is contained in:
Titan
2016-10-27 09:53:14 +08:00
parent fff23e5335
commit f7c4e50fc1
3 changed files with 58 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for nanomsg 3.2.3
// Project: https://github.com/nickdesaulniers/node-nanomsg
// Definitions by: Titan <https://github.com/titan>
// Definitions: https://github.com/DefinitelyTyped/nanomsg
/// <reference types="node" />
declare module "nanomsg" {
export interface EventCallback {
(data: Buffer): void;
}
export class Socket {
constructor(type: string, opts: Object);
shutdown(addr: string): void;
bind(addr: string): void;
connect(addr: string): void;
close(): void;
send(buf: Buffer | string): number;
on(event: string, cb: EventCallback): void;
}
export function socket(type: string, opts?: Object): Socket;
}
+17
View File
@@ -0,0 +1,17 @@
import { Socket, socket } from "nanomsg";
const pub: Socket = socket("pub");
const sub: Socket = socket("sub");
const addr: string = "tcp://127.0.0.1:7789"
pub.bind(addr);
sub.connect(addr);
sub.on('data', function (buf) {
console.log(String(buf));
pub.close();
sub.close();
});
setTimeout(function () {
pub.send("Hello from nanomsg!");
}, 100);
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"nanomsg-tests.ts"
]
}