Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any TypeScript definitions for this? #3

Open
VictorioBerra opened this issue May 28, 2019 · 6 comments
Open

Any TypeScript definitions for this? #3

VictorioBerra opened this issue May 28, 2019 · 6 comments

Comments

@VictorioBerra
Copy link

No description provided.

@jasonpincin
Copy link
Owner

Hm. I don’t see any. Do you?

@VictorioBerra
Copy link
Author

many times they are community provided, or stored in a separate module/repository.

I would like to have some so maybe we can add a help wanted label and if anyone has created a few for use in their own projects they can link them here.

@VictorioBerra
Copy link
Author

Here is a start for the promise side:

declare module 'concurrent-queue' {

    interface LimitConfig {
        concurrency?: number;
        maxSize?: number;
        softMaxSize?: number;
    }

    export default function cq(): cqImpl;

    export interface cqImpl {
        process(processor: (task: any) => Promise<any>): queue;
        limit(limitConfig: LimitConfig): cqImpl;
    }

    export interface queue {
        (item: any): Promise<any>;
    }

}

@bentorkington
Copy link

Thanks @VictorioBerra. If anyone else needs this, I got this down to:

declare module 'concurrent-queue' {
  interface LimitConfig {
    concurrency?: number;
    maxSize?: number;
    softMaxSize?: number;
  }

  export default function cq(): Queue<any>;

  export interface Queue<T> {
    process<T>(processor: (task: any) => Promise<T>): Queue<T>;
    limit(limitConfig: LimitConfig): Queue<T>;
    (item: any): Promise<T>;
    /** the number of queued items */
    size: number;
    pending: T[];
    drained: (cb: () => void) => void;
    processingEnded: (cb: () => void) => void;
  }
}

which better reflects the two fluent methods (it's just as valid to call process() before limit), and ensures the process() call returns a typed Queue<T>, which in turn means queue(item) returns a promise of the same type as the func passed to process()

@bentorkington
Copy link

@jasonpincin would you be interested in a PR to add these (to be completed) Typescript defs?

@jasonpincin
Copy link
Owner

@bentorkington Yes! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants