1.3.5 • Published 6 months ago

@types/reconnect-core v1.3.5

Weekly downloads
291
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/reconnect-core

Summary

This package contains type definitions for reconnect-core (https://github.com/juliangruber/reconnect-core).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/reconnect-core.

index.d.ts

// Type definitions for reconnect-core 1.3
// Project: https://github.com/juliangruber/reconnect-core
// Definitions by: James Bromwell <https://github.com/thw0rted>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

import { Backoff, ExponentialOptions  } from "backoff";
import { EventEmitter } from "events";
import { Stream } from "stream";

declare namespace reconnect {
    // TODO: Once DT supports TS 3.0, use new Generic Rest Parameter feature for
    // ArgType.  Current definitions only support one parameter passed to
    // connect() but the library actually allows any number of args.
    type CustomModule<ArgType, ConnectionType> =
        (opts?: ModuleOptions<ConnectionType>, cb?: (con: ConnectionType) => void) => Instance<ArgType, ConnectionType>;

    interface ModuleOptions<ConnectionType> extends ExponentialOptions {
        immediate?: boolean | undefined;
        failAfter?: number | undefined;
        onConnect?: ((con: ConnectionType) => void) | undefined;
        strategy?: "fibonacci" | "exponential" | Backoff | undefined;
    }

    interface Instance<ArgType, ConnectionType> extends EventEmitter {
        connect(opts: ArgType): this;
        listen(opts: ArgType): this;
        disconnect(): this;
        reset(): void;

        readonly connected: boolean;
        reconnect: boolean;

        on(event: "backoff", cb: (n: number, delay: number, err?: any) => void): this;
        on(event: "connect" | "connection", cb: (con: ConnectionType) => void): this;
        on(event: "disconnect", cb: (err?: any) => void): this;
        on(event: "error" | "fail", cb: (err: any) => void): this;
        on(event: "reconnect", cb: (n: number, delay: number) => void): this;
    }
}

type ConnectFunction<ArgType, ConnectionType> =
    (this: reconnect.Instance<ArgType, ConnectionType>, opts: ArgType) => ConnectionType;
declare function reconnect<ArgType, ConnectionType>(
    cf: ConnectFunction<ArgType, ConnectionType>): reconnect.CustomModule<ArgType, ConnectionType>;

export = reconnect;

Additional Details

  • Last updated: Thu, 08 Jul 2021 22:41:48 GMT
  • Dependencies: @types/backoff
  • Global values: none

Credits

These definitions were written by James Bromwell.

1.3.5

6 months ago

1.3.4

7 months ago

1.3.3

8 months ago

1.3.2

3 years ago

1.3.1

5 years ago

1.3.0

6 years ago