Skip to content

Use ember-concurrency v2 decorator syntax #4069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions app/components/email-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class EmailInput extends Component {
@tracked isEditing = false;
@tracked disableResend = false;

@task(function* () {
@task *resendEmailTask() {
try {
yield this.args.user.resendVerificationEmail();
this.disableResend = true;
Expand All @@ -23,16 +23,15 @@ export default class EmailInput extends Component {
this.notifications.error('Unknown error in resending message');
}
}
})
resendEmailTask;
}

@action
editEmail() {
this.value = this.args.user.email;
this.isEditing = true;
}

@task(function* () {
@task *saveEmailTask() {
let userEmail = this.value;
let user = this.args.user;

Expand All @@ -49,6 +48,5 @@ export default class EmailInput extends Component {

this.notifications.error(`Error in saving email: ${msg}`);
}
})
saveEmailTask;
}
}
5 changes: 2 additions & 3 deletions app/components/follow-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class extends Component {
}).drop())
followStateTask;

@task(function* () {
@task *toggleFollowTask() {
let crate = this.args.crate;

try {
Expand All @@ -42,6 +42,5 @@ export default class extends Component {
} crate. Please try again later!`,
);
}
})
toggleFollowTask;
}
}
10 changes: 4 additions & 6 deletions app/components/pending-owner-invite-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class PendingOwnerInviteRow extends Component {
@tracked isAccepted = false;
@tracked isDeclined = false;

@task(function* () {
@task *acceptInvitationTask() {
this.args.invite.set('accepted', true);

try {
Expand All @@ -23,10 +23,9 @@ export default class PendingOwnerInviteRow extends Component {
this.notifications.error('Error in accepting invite');
}
}
})
acceptInvitationTask;
}

@task(function* () {
@task *declineInvitationTask() {
this.args.invite.set('accepted', false);

try {
Expand All @@ -39,6 +38,5 @@ export default class PendingOwnerInviteRow extends Component {
this.notifications.error('Error in declining invite');
}
}
})
declineInvitationTask;
}
}
10 changes: 4 additions & 6 deletions app/components/settings/api-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ApiTokens extends Component {
this.newToken = this.store.createRecord('api-token');
}

@task(function* () {
@task *saveTokenTask() {
let token = this.newToken;

try {
Expand All @@ -34,10 +34,9 @@ export default class ApiTokens extends Component {

this.notifications.error(msg);
}
})
saveTokenTask;
}

@task(function* (token) {
@task *revokeTokenTask(token) {
try {
yield token.destroyRecord();
this.args.tokens.removeObject(token);
Expand All @@ -49,6 +48,5 @@ export default class ApiTokens extends Component {

this.notifications.error(msg);
}
})
revokeTokenTask;
}
}
11 changes: 4 additions & 7 deletions app/controllers/crate/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class CrateSettingsController extends Controller {
crate = null;
username = '';

@task(function* () {
@task *addOwnerTask() {
const username = this.username;

try {
Expand All @@ -22,10 +22,8 @@ export default class CrateSettingsController extends Controller {
this.notifications.error('Error sending invite');
}
}
})
addOwnerTask;

@task(function* (owner) {
}
@task *removeOwnerTask(owner) {
try {
yield this.crate.removeOwner(owner.get('login'));

Expand All @@ -45,6 +43,5 @@ export default class CrateSettingsController extends Controller {

this.notifications.error(message);
}
})
removeOwnerTask;
}
}
5 changes: 2 additions & 3 deletions app/controllers/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class CrateVersionController extends Controller {

@alias('loadReadmeTask.last.value') readme;

@task(function* () {
@task *loadReadmeTask() {
let version = this.currentVersion;

let readme = version.loadReadmeTask.lastSuccessful
Expand All @@ -41,6 +41,5 @@ export default class CrateVersionController extends Controller {
}

return readme;
})
loadReadmeTask;
}
}
5 changes: 2 additions & 3 deletions app/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export default class DashboardController extends Controller {
return this.myFollowing.length > TO_SHOW;
}

@task(function* () {
@task *loadMoreTask() {
let page = this.myFeed.length / 10 + 1;

let data = yield ajax(`/api/v1/me/updates?page=${page}`);
let versions = data.versions.map(version => this.store.push(this.store.normalize('version', version)));

this.myFeed.pushObjects(versions);
this.set('hasMore', data.meta.more);
})
loadMoreTask;
}
}
5 changes: 2 additions & 3 deletions app/models/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ export default class Version extends Model {
}).keepLatest())
loadReadmeTask;

@task(function* () {
@task *loadDocsBuildsTask() {
return yield ajax(`https://docs.rs/crate/${this.crateName}/${this.num}/builds.json`);
})
loadDocsBuildsTask;
}

@computed('loadDocsBuildsTask.lastSuccessful.value')
get hasDocsRsLink() {
Expand Down
5 changes: 2 additions & 3 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export default class ApplicationRoute extends Route {
return true;
}

@task(function* () {
@task *preloadPlaygroundCratesTask() {
yield rawTimeout(1000);
yield this.playground.loadCratesTask.perform();
})
preloadPlaygroundCratesTask;
}
}
12 changes: 5 additions & 7 deletions app/services/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { htmlSafe } from '@ember/template';
import { tracked } from '@glimmer/tracking';
import Ember from 'ember';

import { didCancel, rawTimeout, task } from 'ember-concurrency';
import { didCancel, dropTask, rawTimeout, task } from 'ember-concurrency';

const SPEED = 200;

Expand All @@ -24,7 +24,7 @@ export default class ProgressService extends Service {
});
}

@task(function* (promise) {
@task *counterTask(promise) {
this.updateTask.perform().catch(error => {
if (!didCancel(error)) {
// this task shouldn't be able to fail, but if it does we'll let Sentry know
Expand All @@ -33,10 +33,9 @@ export default class ProgressService extends Service {
});

yield promise;
})
counterTask;
}

@(task(function* () {
@dropTask *updateTask() {
if (Ember.testing) return;

let progress = 0;
Expand Down Expand Up @@ -69,6 +68,5 @@ export default class ProgressService extends Service {
this._style = `transition: width ${SPEED}ms linear; width: 100%`;
yield rawTimeout(SPEED);
this._style = `transition: opacity ${SPEED * 2}ms linear; width: 100%; opacity: 0`;
}).drop())
updateTask;
}
}
22 changes: 9 additions & 13 deletions app/services/session.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { alias } from '@ember/object/computed';
import Service, { inject as service } from '@ember/service';

import { race, rawTimeout, task, waitForEvent } from 'ember-concurrency';
import { dropTask, race, rawTimeout, task, waitForEvent } from 'ember-concurrency';
import window from 'ember-window-mock';

import ajax from '../utils/ajax';
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class SessionService extends Service {
* @see https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access
* @see `github-authorize` route
*/
@task(function* () {
@task *loginTask() {
let windowDimensions = [
'width=1000',
'height=450',
Expand Down Expand Up @@ -109,20 +109,18 @@ export default class SessionService extends Service {
if (transition) {
transition.retry();
}
})
loginTask;
}

@task(function* (window) {
@task *windowCloseWatcherTask(window) {
while (true) {
if (window.closed) {
return { closed: true };
}
yield rawTimeout(10);
}
})
windowCloseWatcherTask;
}

@task(function* () {
@task *logoutTask() {
yield ajax(`/api/private/session`, { method: 'DELETE' });

this.savedTransition = null;
Expand All @@ -132,10 +130,9 @@ export default class SessionService extends Service {
this.sentry.setUser(null);

this.router.transitionTo('index');
})
logoutTask;
}

@(task(function* () {
@dropTask *loadUserTask() {
if (!this.isLoggedIn) return {};

let response;
Expand All @@ -152,6 +149,5 @@ export default class SessionService extends Service {
this.sentry.setUser({ id });

return { currentUser, ownedCrates };
}).drop())
loadUserTask;
}
}