Skip to content

Commit

Permalink
[promise-limit_v2.x.x] Add libdefs for promise-limit (#3044)
Browse files Browse the repository at this point in the history
* Add types for promise-limit

* Add type assertion

* Wrap tests in describe/it, as suggested
  • Loading branch information
nvie authored and villesau committed Jan 6, 2019
1 parent 5848599 commit eec3ba4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
@@ -0,0 +1,21 @@
/**
* Flow libdef for 'promise-limit'
* See https://www.npmjs.com/package/promise-limit
* by Vincent Driessen, 2019-01-04
*/

declare module 'promise-limit' {
declare type limit<T> = limitFunc<T> & limitInterface<T>;
declare type limitFunc<T> = (fn: () => Promise<T>) => Promise<T>;
declare interface limitInterface<T> {
map<U>(
items: $ReadOnlyArray<T>,
mapper: (value: T) => Promise<U>,
): Promise<Array<U>>;
queue: number;
}

declare export default function limitFactory<T>(
concurrency?: number,
): limit<T>;
}
21 changes: 21 additions & 0 deletions definitions/npm/promise-limit_v2.x.x/test_promise-limit_v2.x.x.js
@@ -0,0 +1,21 @@
// @flow strict

import { describe, it } from "flow-typed-test";
import limit from "promise-limit";

describe("promise-limit", () => {
it("errors", () => {
// $ExpectError
limit("");
});

it("works", () => {
const limiter = limit(3);

function dosomething_(): Promise<string> {
return Promise.resolve("hi");
}
const dosomething = () => limiter(() => dosomething_());
(dosomething: () => Promise<string>);
});
});

0 comments on commit eec3ba4

Please sign in to comment.