Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

[WIP] feat(async): fix #740, use async hooks to wrap nodejs async api #795

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
sudo: false
node_js:
- '6.3.1'
- '8'
env:
global:
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready
Expand Down Expand Up @@ -34,5 +34,7 @@ script:
- node_modules/.bin/karma start karma-dist-sauce-selenium3-jasmine.conf.js --single-run
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
- node_modules/.bin/gulp test/node
- node_modules/.bin/gulp test/node/asynchooks
- node_modules/.bin/gulp test/node/es2017
- node simple-server.js 2>&1> server.log&
- node ./test/webdriver/test.sauce.js
18 changes: 18 additions & 0 deletions example/benchmarks/timeout_benchmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
require('../../dist/zone-node-asynchooks');

const start = Date.now();
for (let i = 0; i < 100000; i ++) {
setTimeout(() => {}, 0);
}

setTimeout(() => {
const end = Date.now();
console.log('cost: ', (end - start));
}, 100);
31 changes: 28 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ gulp.task('compile-node', function(cb) {
tsc('tsconfig-node.json', cb);
});

gulp.task('compile-node-es2017', function(cb) {
tsc('tsconfig-node.es2017.json', cb);
});

gulp.task('compile-esm', function(cb) {
tsc('tsconfig-esm.json', cb);
});
Expand Down Expand Up @@ -128,6 +132,15 @@ gulp.task('build/zone-mix.js', ['compile-esm-node'], function(cb) {
return generateScript('./lib/mix/rollup-mix.ts', 'zone-mix.js', false, cb);
});

// Zone for node asynchooks environment.
gulp.task('build/zone-node-asynchooks.js', ['compile-esm-node'], function(cb) {
return generateScript('./lib/node/rollup-main-asynchooks.ts', 'zone-node-asynchooks.js', false, cb);
});

gulp.task('build/zone-node-asynchooks.min.js', ['compile-esm-node'], function(cb) {
return generateScript('./lib/node/rollup-main-asynchooks.ts', 'zone-node-asynchooks.js', true, cb);
});

gulp.task('build/zone-error.js', ['compile-esm'], function(cb) {
return generateScript('./lib/common/error-rewrite.ts', 'zone-error.js', false, cb);
});
Expand Down Expand Up @@ -287,6 +300,8 @@ gulp.task('build', [
'build/zone-patch-cordova.min.js',
'build/zone-patch-electron.js',
'build/zone-patch-electron.min.js',
'build/zone-node-asynchooks.js',
'build/zone-node-asynchooks.min.js',
'build/zone-mix.js',
'build/bluebird.js',
'build/bluebird.min.js',
Expand All @@ -310,12 +325,10 @@ gulp.task('build', [
'build/closure.js'
]);

gulp.task('test/node', ['compile-node'], function(cb) {
function runJasmineTest(specFiles, cb) {
var JasmineRunner = require('jasmine');
var jrunner = new JasmineRunner();

var specFiles = ['build/test/node_entry_point.js'];

jrunner.configureDefaultReporter({showColors: true});

jrunner.onComplete(function(passed) {
Expand All @@ -336,6 +349,18 @@ gulp.task('test/node', ['compile-node'], function(cb) {
jrunner.specDir = '';
jrunner.addSpecFiles(specFiles);
jrunner.execute();
}

gulp.task('test/node/es2017', ['compile-node-es2017'], function(cb) {
runJasmineTest(['build/test/node_entry_point_es2017.js'], cb);
});

gulp.task('test/node/asynchooks', ['compile-node'], function(cb) {
runJasmineTest(['build/test/node_entry_point_asynchooks.js'], cb);
});

gulp.task('test/node', ['compile-node'], function(cb) {
runJasmineTest(['build/test/node_entry_point.js'], cb);
});

// Check the coding standards and programming errors
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OBJECT = 'object';
const UNDEFINED = 'undefined';

export function propertyPatch() {
Object.defineProperty = function(obj, prop, desc) {
Object.defineProperty = function(obj: any, prop: string, desc: any) {
if (isUnconfigurable(obj, prop)) {
throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
}
Expand All @@ -49,7 +49,7 @@ export function propertyPatch() {
return _create(obj, proto);
};

Object.getOwnPropertyDescriptor = function(obj, prop) {
Object.getOwnPropertyDescriptor = function(obj: any, prop: string) {
const desc = _getOwnPropertyDescriptor(obj, prop);
if (isUnconfigurable(obj, prop)) {
desc.configurable = false;
Expand Down
Loading