mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
Add typings for nanomsg
This commit is contained in:
Vendored
+22
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user