Skip to content

Commit

Permalink
Merge pull request #363 from jamescdavis/tasks_are_ember_objects
Browse files Browse the repository at this point in the history
Types: Make Task, TaskInstance, and TaskGroup extend EmberObject
  • Loading branch information
maxfierke authored Jun 23, 2020
2 parents d066cd7 + 94165a2 commit fac0f13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions addon/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EmberObject from '@ember/object';
import ComputedProperty from '@ember/object/computed';

export type TaskGenerator<T> = Generator<any, T, any>;
Expand Down Expand Up @@ -29,7 +30,7 @@ export type EncapsulatedTaskDescriptorReturnType<T extends EncapsulatedTaskDescr
* method on this object to cancel all running or enqueued
* {@linkcode TaskInstance}s.
*/
export interface Task<T, Args extends any[]> {
export interface Task<T, Args extends any[]> extends EmberObject {
/**
* `true` if any current task instances are running.
*/
Expand Down Expand Up @@ -141,7 +142,7 @@ export interface Task<T, Args extends any[]> {
* });
* ```
*/
export interface TaskGroup<T> {
export interface TaskGroup<T> extends EmberObject {
/**
* `true` if any current task instances are running.
*/
Expand Down Expand Up @@ -234,7 +235,7 @@ export interface TaskGroup<T> {
* because concurrency policy enforced by a
* {@linkcode TaskProperty Task Modifier} canceled the task instance.
*/
export interface TaskInstance<T> extends Promise<T> {
export interface TaskInstance<T> extends Promise<T>, EmberObject {
/**
* If this TaskInstance runs to completion by returning a property
* other than a rejecting promise, this property will be set
Expand Down
18 changes: 18 additions & 0 deletions tests/types/ember-concurrency-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ module('unit tests', () => {
expect(t.lastIncomplete).toEqualTypeOf<MyTaskInstance | null>();
expect(t.performCount).toBeNumber();

expect(t.get).toBeCallableWith('isRunning');
expect(t.get('isRunning')).toBeBoolean();

// @ts-expect-error
t.get('nonexistentProperty');

expect(t.cancelAll).toBeCallableWith();
expect(t.cancelAll).toBeCallableWith({});
expect(t.cancelAll).toBeCallableWith({ reason: 'why do you care' });
Expand Down Expand Up @@ -168,6 +174,12 @@ module('unit tests', () => {
expect(tg.lastIncomplete).toEqualTypeOf<MyTaskInstance | null>();
expect(tg.performCount).toBeNumber();

expect(tg.get).toBeCallableWith('isRunning');
expect(tg.get('isRunning')).toEqualTypeOf<boolean>()

// @ts-expect-error
tg.get('nonexistentProperty');

expect(tg.cancelAll).toBeCallableWith();
expect(tg.cancelAll).toBeCallableWith({});
expect(tg.cancelAll).toBeCallableWith({ reason: 'why do you care' });
Expand Down Expand Up @@ -206,6 +218,12 @@ module('unit tests', () => {
expect(t.state).toEqualTypeOf<'dropped' | 'canceled' | 'finished' | 'running' | 'waiting'>();
expect(t.isDropped).toBeBoolean();

expect(t.get).toBeCallableWith('value');
expect(t.get('value')).toEqualTypeOf<string | null>()

// @ts-expect-error
t.get('nonexistentProperty');

expect(t.cancel).toBeCallableWith();
expect(t.cancel).toBeCallableWith('why do you care');
expect(t.cancel).parameters.toEqualTypeOf<[string?]>();
Expand Down

0 comments on commit fac0f13

Please sign in to comment.