Socket
Socket
Sign inDemoInstall

egg-core

Package Overview
Dependencies
Maintainers
4
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-core - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

5

History.md
1.7.0 / 2017-01-26
==================
* feat: add app.beforeClose to register close function (#43)
1.6.0 / 2017-01-20

@@ -3,0 +8,0 @@ ==================

44

lib/egg.js

@@ -11,5 +11,8 @@ 'use strict';

const BaseContextClass = require('./utils/base_context_class');
const utils = require('./utils');
const DEPRECATE = Symbol('EggCore#deprecate');
const CLOSESET = Symbol('EggCore#closeSet');
const ISCLOSE = Symbol('EggCore#isClose');

@@ -51,2 +54,5 @@ class EggCore extends KoaApplication {

// register a close set
this[CLOSESET] = new Set();
/**

@@ -162,13 +168,31 @@ * BaseContextClass is a base class extended by classes(like service and controller),

close() {
return new Promise((resolve, reject) => {
try {
this.emit('close');
this.removeAllListeners();
resolve();
} catch (err) {
reject(err);
return co(function* () {
if (this[ISCLOSE] === true) return;
// custom close
for (const fn of this[CLOSESET]) {
yield utils.callFn(fn);
}
});
this.emit('close');
this.removeAllListeners();
this[ISCLOSE] = true;
}.bind(this));
}
/**
* register a function that will be called when app close
* @param {Function} fn - the function that can be generator function or async function
* @return {Boolean} status - whether registered or not
*/
beforeClose(fn) {
assert(is.function(fn), 'argument should be function');
this[CLOSESET].add(fn);
return true;
}
/**
* return base controller
* @member {Controller}
*/
get Controller() {

@@ -178,2 +202,6 @@ return this.BaseContextClass;

/**
* return base service
* @member {Service}
*/
get Service() {

@@ -180,0 +208,0 @@ return this.BaseContextClass;

@@ -5,3 +5,5 @@ 'use strict';

const homedir = require('node-homedir');
const is = require('is-type-of');
module.exports = {

@@ -45,2 +47,15 @@

},
* callFn(fn, args) {
args = args || [];
if (!is.function(fn)) return;
if (is.generatorFunction(fn)) {
return yield fn(...args);
}
const r = fn(...args);
if (is.promise(r)) {
return yield r;
}
return r;
},
};

3

package.json
{
"name": "egg-core",
"version": "1.6.0",
"version": "1.7.0",
"description": "A core Pluggable framework based on koa",

@@ -10,2 +10,3 @@ "main": "index.js",

"test": "npm run lint && egg-bin test",
"test-local": "egg-bin test",
"cov": "egg-bin cov",

@@ -12,0 +13,0 @@ "ci": "npm run lint && npm run cov"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc