Skip to content

Commit 8dc558c

Browse files
authored
fix(components): remove deprecated @task decorator (#3117)
1 parent 0d8a483 commit 8dc558c

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

packages/components/src/components/hds/time/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ export default class HdsTime extends Component<HdsTimeSignature> {
129129
}
130130

131131
@action
132-
didInsertNode(): void {
132+
async didInsertNode(): Promise<void> {
133133
const date = this.date;
134134

135135
if (dateIsValid(date)) {
136-
this.hdsTime.register(date);
136+
await this.hdsTime.register(date);
137137
}
138138
}
139139

packages/components/src/services/hds-time.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
*/
55

66
import Service from '@ember/service';
7-
import { task, timeout } from 'ember-concurrency';
7+
import { dropTask, timeout } from 'ember-concurrency';
88
import { tracked } from '@glimmer/tracking';
99
import { DateTime } from 'luxon';
1010
import { isTesting } from '@embroider/macros';
11-
import type { TaskGenerator } from 'ember-concurrency';
1211
import type {
1312
DisplayType,
1413
DefaultDisplayType,
@@ -226,12 +225,11 @@ export default class TimeService extends Service {
226225
}
227226

228227
// Subscribes a listener to the ticking task for time changes.
229-
register(id: Date): () => void {
228+
async register(id: Date): Promise<() => void> {
230229
this.#listeners.add(id);
231-
// @ts-expect-error - TS2339: Property 'perform' does not exist on type '() => TaskGenerator<string | undefined>'
232-
// note: we could potentially use taskFor via `ember-concurrency-ts` to avoid this exception
233-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
234-
this.start.perform();
230+
231+
await this.start.perform();
232+
235233
return (): void => {
236234
this.unregister(id);
237235
};
@@ -242,18 +240,17 @@ export default class TimeService extends Service {
242240
return this.#listeners.delete(id);
243241
}
244242

245-
@task({ drop: true })
246-
*start(): TaskGenerator<string | undefined> {
243+
start = dropTask(async () => {
247244
while (this.listeners.size) {
248245
this.now = Date.now();
249246
// When testing and canceling a EC task, a timer will never resolve and
250247
// cause the test to hang while waiting for a permanently hanging timeout.
251248
// This condition breaks the test out of that.
252249
// via: http://ember-concurrency.com/docs/testing-debugging/
253250
if (isTesting()) return;
254-
yield timeout(SECOND_IN_MS);
251+
await timeout(SECOND_IN_MS);
255252
}
256-
}
253+
});
257254

258255
// Transforms a JS date to a string representing the UTC ISO date.
259256
toIsoUtcString(date: Date): string | undefined {

showcase/tests/unit/services/hds-time-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module('Unit | Service | time', function (hooks) {
112112
);
113113
});
114114

115-
test(`it can register and unregister listeners`, function (assert) {
115+
test(`it can register and unregister listeners`, async function (assert) {
116116
let id = Date.now();
117117
assert.strictEqual(
118118
this.service.listeners.size,
@@ -123,7 +123,7 @@ module('Unit | Service | time', function (hooks) {
123123
this.service.listeners.has(id),
124124
'the registered id does not exist yet',
125125
);
126-
let unregister = this.service.register(id);
126+
let unregister = await this.service.register(id);
127127
assert.ok(this.service.listeners.has(id), 'the registered id exists');
128128
assert.strictEqual(
129129
this.service.listeners.size,

0 commit comments

Comments
 (0)