Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Nov 7, 2017
1 parent d861bc4 commit 8dc67df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
2 changes: 2 additions & 0 deletions test/egg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ describe('test/egg.test.js', () => {
assert(app.beforeStartFunction === false);
assert(app.beforeStartGeneratorFunction === false);
assert(app.beforeStartAsyncFunction === false);
assert(app.beforeStartTranslateAsyncFunction === false);
yield app.ready();
assert(app.beforeStartFunction === true);
assert(app.beforeStartGeneratorFunction === true);
assert(app.beforeStartAsyncFunction === true);
assert(app.beforeStartTranslateAsyncFunction === true);
});

it('should beforeStart excute success with EGG_READY_TIMEOUT_ENV', function* () {
Expand Down
9 changes: 7 additions & 2 deletions test/fixtures/beforestart/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ module.exports = function (app) {
app.beforeStart(function () {
return __awaiter(this, void 0, void 0, function* () {
yield sleep(1000);
app.beforeStartAsyncFunction = true;
app.beforeStartTranslateAsyncFunction = true;
});
});
app.beforeStart(async () => {
await sleep(1000);
app.beforeStartAsyncFunction = true;
});
app.beforeStartFunction = false;
app.beforeStartAsyncFunction = false;
app.beforeStartTranslateAsyncFunction = false;
app.beforeStartGeneratorFunction = false;
app.beforeStartAsyncFunction = false;
};
16 changes: 2 additions & 14 deletions test/fixtures/router-app/app/controller/async.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
'use strict';

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};

module.exports = app => {
return class AsyncController extends app.Controller {
index() {
const ctx = this.ctx;
return __awaiter(this, void 0, void 0, function* () {
ctx.body.push('async');
});
async index() {
this.ctx.body.push('async');
}
}
};
19 changes: 4 additions & 15 deletions test/fixtures/router-app/app/middleware/async.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
'use strict';

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};

module.exports = function() {
return function(ctx, next) {
return __awaiter(this, void 0, void 0, function* () {
yield next();
ctx.body.push('async');
});
}
return async (ctx, next) => {
await next();
ctx.body.push('async');
};
};

0 comments on commit 8dc67df

Please sign in to comment.