Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Task.resolve() returns a Task
Browse files Browse the repository at this point in the history
Fixes #153
  • Loading branch information
kitsonk committed Apr 25, 2016
1 parent a7565bb commit 9d39c1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/async/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default class Task<T> extends Promise<T> {
static resolve(): Task<void>;
static resolve<T>(value: (T | Thenable<T>)): Task<T>;
static resolve<T>(value?: any): Task<T> {
return <any> super.resolve(value);
return new this((resolve) => {
resolve(value);
});
}

protected static copy<U>(other: Promise<U>): Task<U> {
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/async/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ let suite = {

resolver();
}
},

'Task#resolve': {
'returns a task'() {
const task = Task.resolve('foo');

assert.isFunction(task.cancel, 'A task should have a cancel function');
assert.isFunction(task.finally, 'A task should have a finally function');

return task.then((result) => {
assert.strictEqual(result, 'foo', 'result should equal "foo"');
});
}
}
};

Expand Down

0 comments on commit 9d39c1d

Please sign in to comment.