Skip to content

Commit

Permalink
Support wrapping functions not returning promises.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrv committed Jul 13, 2017
1 parent fa1d5c7 commit cbcf2d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function tryFinally<PromiseType extends Promisy<PromiseType>>(
promise = func();

// Ensure func return value is a promise.
if(typeof(promise.then) != 'function') {
if(typeof(promise) != 'object' || typeof(promise.then) != 'function') {
promise = Promise.resolve(promise);
}
} catch(err) {
Expand Down
4 changes: 2 additions & 2 deletions src/TaskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TaskQueue<PromiseType extends Promisy<PromiseType>> {
* @param func Function to call.
* @param delay Initial delay in milliseconds before making the call. */

add(func: () => PromiseType, delay = 0) {
add(func: () => any, delay = 0) {
if(this.busyCount < this.concurrency && !delay) {
// Start the task immediately.

Expand Down Expand Up @@ -57,7 +57,7 @@ export class TaskQueue<PromiseType extends Promisy<PromiseType>> {
/** Wrap a function returning a promise, so that before running
* it waits until concurrent invocations are below this queue's limit. */

wrap(func: (...args: any[]) => PromiseType, thisObject?: any) {
wrap(func: (...args: any[]) => any, thisObject?: any) {
return((...args: any[]) => this.add(() => func.apply(thisObject, args)));
}

Expand Down

0 comments on commit cbcf2d3

Please sign in to comment.