Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'egg-core' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
_runInBackground(scope) {
const ctx = this;
const start = Date.now();
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
// use app.toAsyncFunction to support both generator function and async function
return ctx.app.toAsyncFunction(scope)(ctx)
.then(() => {
ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start);
})
.catch(err => {
// background task process log
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start);
// emit error when promise catch, and set err.runInBackground flag
err.runInBackground = true;
ctx.app.emit('error', err, ctx);
});
},
};
_runInBackground(scope) {
const ctx = this;
const start = Date.now();
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
// use app.toAsyncFunction to support both generator function and async function
return ctx.app.toAsyncFunction(scope)(ctx)
.then(() => {
ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start);
})
.catch(err => {
// background task process log
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start);
// emit error when promise catch, and set err.runInBackground flag
err.runInBackground = true;
ctx.app.emit('error', err, ctx);
});
},
};
runInBackground(scope) {
// try to use custom function name first
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
scope._name = taskName;
this._runInBackground(scope);
},
runInBackground(scope) {
// try to use custom function name first
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
scope._name = taskName;
this._runInBackground(scope);
},
'use strict';
const path = require('path');
const fs = require('fs');
const ms = require('ms');
const is = require('is-type-of');
const graceful = require('graceful');
const http = require('http');
const cluster = require('cluster-client');
const onFinished = require('on-finished');
const { assign } = require('utility');
const eggUtils = require('egg-core').utils;
const EggApplication = require('./egg');
const AppWorkerLoader = require('./loader').AppWorkerLoader;
const KEYS = Symbol('Application#keys');
const HELPER = Symbol('Application#Helper');
const LOCALS = Symbol('Application#locals');
const BIND_EVENTS = Symbol('Application#bindEvents');
const WARN_CONFUSED_CONFIG = Symbol('Application#warnConfusedConfig');
const EGG_LOADER = Symbol.for('egg#loader');
const EGG_PATH = Symbol.for('egg#eggPath');
const CLUSTER_CLIENTS = Symbol.for('egg#clusterClients');
const RESPONSE_RAW = Symbol('Application#responseRaw');
// client error => 400 Bad Request
// Refs: https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_event_clienterror
const DEFAULT_BAD_REQUEST_HTML = `
'use strict';
// try to use eggUtils.getCalleeFromStack
// ignore it if egg-core module not found
let eggUtils;
try {
eggUtils = require('egg-core').utils;
if (!eggUtils) {
// try to support egg-core@3
eggUtils = require('egg-core/lib/utils');
}
} catch (_) {
// ignore eggUtils
}
module.exports = {
runInBackground(scope) {
/* istanbul ignore next */
const taskName = scope._name || scope.name || (eggUtils && eggUtils.getCalleeFromStack(true));
if (taskName) {
scope._name = taskName;
}
onClientError(err, socket) {
// ignore when there is no http body, it almost like an ECONNRESET
if (err.rawPacket) {
this.logger.warn('A client (%s:%d) error [%s] occurred: %s',
socket.remoteAddress,
socket.remotePort,
err.code,
err.message);
}
if (typeof this.config.onClientError === 'function') {
const p = eggUtils.callFn(this.config.onClientError, [ err, socket, this ]);
// the returned object should like:
//
// {
// body: '...',
// headers: {
// ...
// },
// status: 400
// }
//
// default values:
//
// + body: ''
// + headers: {}
// + status: 400
'use strict';
const fs = require('fs');
const path = require('path');
const rimraf = require('mz-modules/rimraf');
const eggPath = path.join(__dirname, 'node_modules/egg-core');
rimraf.sync(eggPath);
fs.symlinkSync(
path.join(__dirname, '../../..'),
eggPath,
'dir'
);
const EggCore = require('egg-core').EggCore;
const EggLoader = require('egg-core').EggLoader;
class AppLoader extends EggLoader {
loadAll() {
this.loadPlugin();
this.loadConfig();
this.loadApplicationExtend();
this.loadContextExtend();
this.loadRequestExtend();
this.loadResponseExtend();
this.loadBootHook();
this.loadCustomApp();
this.loadMiddleware();
this.loadService();
this.loadController();
this.loadRouter();
}
'use strict';
const fs = require('fs');
const path = require('path');
const rimraf = require('mz-modules/rimraf');
const eggPath = path.join(__dirname, 'node_modules/egg-core');
rimraf.sync(eggPath);
fs.symlinkSync(
path.join(__dirname, '../../..'),
eggPath,
'dir'
);
const EggCore = require('egg-core').EggCore;
const EggLoader = require('egg-core').EggLoader;
class AppLoader extends EggLoader {
loadAll() {
this.loadPlugin();
this.loadConfig();
this.loadApplicationExtend();
this.loadContextExtend();
this.loadRequestExtend();
this.loadResponseExtend();
this.loadCustomApp();
this.loadMiddleware();
this.loadService();
this.loadController();
this.loadRouter();
}
}
'use strict';
const fs = require('fs');
const path = require('path');
const rimraf = require('mz-modules/rimraf');
const eggPath = path.join(__dirname, 'node_modules/egg-core');
rimraf.sync(eggPath);
fs.symlinkSync(
path.join(__dirname, '../../..'),
eggPath,
'dir'
);
const EggCore = require('egg-core').EggCore;
const EggLoader = require('egg-core').EggLoader;
class AppLoader extends EggLoader {
loadAll() {
this.loadPlugin();
this.loadConfig();
this.loadApplicationExtend();
this.loadContextExtend();
this.loadRequestExtend();
this.loadResponseExtend();
this.loadCustomApp();
this.loadMiddleware();
this.loadService();
this.loadController();
this.loadRouter();
}