smtp-server-as-promised
Advanced tools
Comparing version 4.0.0 to 4.1.0
# Changelog | ||
## v4.1.0 2018-09-10 | ||
* New method `destroy`. | ||
## v4.0.0 2018-09-09 | ||
@@ -4,0 +8,0 @@ |
@@ -24,3 +24,4 @@ /// <reference types="node" /> | ||
server: SMTPServer; | ||
protected onError?: (error: Error) => Promise<void>; | ||
protected closed?: boolean; | ||
protected errorHandler?: (error: Error) => Promise<void>; | ||
constructor(options?: SMTPServerAsPromisedOptions); | ||
@@ -30,3 +31,4 @@ listen(options?: net.ListenOptions): Promise<SMTPServerAsPromisedServerAddress>; | ||
updateSecureContext(options: tls.TlsOptions): void; | ||
destroy(): Promise<void>; | ||
} | ||
export default SMTPServerAsPromised; |
@@ -10,2 +10,3 @@ "use strict"; | ||
constructor(options = {}) { | ||
this.closed = false; | ||
const smtpSeverOptions = Object.assign({}, options); | ||
@@ -54,4 +55,4 @@ if (options.onConnect) { | ||
if (options.onError) { | ||
this.onError = options.onError; | ||
this.server.on('error', this.onError); | ||
this.errorHandler = options.onError; | ||
this.server.on('error', this.errorHandler); | ||
} | ||
@@ -79,9 +80,13 @@ } | ||
this.server.close((err) => { | ||
this.closed = true; | ||
if (this.errorHandler) { | ||
this.server.removeListener('error', this.errorHandler); | ||
this.errorHandler = undefined; | ||
} | ||
if (err) { | ||
return reject(err); | ||
} | ||
if (this.onError) { | ||
this.server.removeListener('error', this.onError); | ||
else { | ||
resolve(); | ||
} | ||
resolve(); | ||
}); | ||
@@ -93,4 +98,12 @@ }); | ||
} | ||
destroy() { | ||
if (!this.closed) { | ||
return this.close(); | ||
} | ||
else { | ||
return Promise.resolve(); | ||
} | ||
} | ||
} | ||
exports.SMTPServerAsPromised = SMTPServerAsPromised; | ||
exports.default = SMTPServerAsPromised; |
{ | ||
"name": "smtp-server-as-promised", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Promisify smtp-server module", | ||
@@ -52,2 +52,3 @@ "main": "lib/smtp-server-as-promised.js", | ||
"promise-socket": "^3.1.1", | ||
"rimraf": "^2.6.2", | ||
"semver": "^5.5.1", | ||
@@ -62,3 +63,3 @@ "ts-node": "^7.0.1", | ||
"clean": "rimraf lib", | ||
"postpublish": "git tag v$npm_package_version -a -m \"Release $npm_package_version\" && git push --tags", | ||
"postpublish": "git tag v$npm_package_version -a -m \"Release v$npm_package_version\" && git push --tags", | ||
"prepublishOnly": "npm run build", | ||
@@ -65,0 +66,0 @@ "pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && markdownlint \"*.md\"", |
@@ -225,2 +225,10 @@ # smtp-server-as-promised | ||
### destroy | ||
```js | ||
await connection.destroy() | ||
``` | ||
Manually free resources taken by server. | ||
## License | ||
@@ -227,0 +235,0 @@ |
@@ -32,3 +32,4 @@ /// <reference types="node" /> | ||
protected onError?: (error: Error) => Promise<void> | ||
protected closed?: boolean = false | ||
protected errorHandler?: (error: Error) => Promise<void> | ||
@@ -82,4 +83,4 @@ constructor (options: SMTPServerAsPromisedOptions = {}) { | ||
if (options.onError) { | ||
this.onError = options.onError | ||
this.server.on('error', this.onError) | ||
this.errorHandler = options.onError | ||
this.server.on('error', this.errorHandler) | ||
} | ||
@@ -113,9 +114,12 @@ } | ||
this.server.close((err?: Error | null) => { | ||
this.closed = true | ||
if (this.errorHandler) { | ||
this.server.removeListener('error', this.errorHandler) | ||
this.errorHandler = undefined | ||
} | ||
if (err) { | ||
return reject(err) | ||
} else { | ||
resolve() | ||
} | ||
if (this.onError) { | ||
this.server.removeListener('error', this.onError) | ||
} | ||
resolve() | ||
}) | ||
@@ -128,4 +132,12 @@ }) | ||
} | ||
destroy (): Promise<void> { | ||
if (!this.closed) { | ||
return this.close() | ||
} else { | ||
return Promise.resolve() | ||
} | ||
} | ||
} | ||
export default SMTPServerAsPromised |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21921
283
238
0
28