knifecycle
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -246,2 +246,3 @@ 'use strict'; | ||
servicesSequence: [], | ||
servicesShutdownsPromises: new Map(), | ||
errorsPromises: [] | ||
@@ -278,5 +279,13 @@ }; | ||
var serviceDescriptor = siloContext.servicesDescriptors.get(serviceName); | ||
var serviceShutdownPromise = siloContext.servicesShutdownsPromises.get(serviceName); | ||
if (serviceShutdownPromise) { | ||
debug('Reusing a service shutdown promise:', serviceName); | ||
return serviceShutdownPromise; | ||
} | ||
debug('Shutting down a service:', serviceName); | ||
return serviceDescriptor.shutdownProvider ? serviceDescriptor.shutdownProvider() : Promise.resolve(); | ||
serviceShutdownPromise = serviceDescriptor.shutdownProvider ? serviceDescriptor.shutdownProvider() : Promise.resolve(); | ||
siloContext.servicesShutdownsPromises.set(serviceName, serviceShutdownPromise); | ||
return serviceShutdownPromise; | ||
})).then(_shutdownNextServices.bind(null, reversedServiceSequence)); | ||
@@ -283,0 +292,0 @@ } |
@@ -369,3 +369,42 @@ 'use strict'; | ||
}); | ||
it('should work with deeper multi used dependencies', function (done) { | ||
var shutdownCallResolve = void 0; | ||
var shutdownResolve = void 0; | ||
var shutdownCallPromise = new Promise(function (resolve) { | ||
shutdownCallResolve = resolve; | ||
}); | ||
var shutdownStub = _sinon2.default.spy(function () { | ||
shutdownCallResolve(); | ||
return new Promise(function (resolve) { | ||
shutdownResolve = resolve; | ||
}); | ||
}); | ||
$.constant('ENV', ENV); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('shutdownChecker', $.depends(['hash'], function () { | ||
return Promise.resolve({ | ||
servicePromise: Promise.resolve({ | ||
shutdownStub: shutdownStub, | ||
shutdownResolve: shutdownResolve | ||
}), | ||
shutdownProvider: shutdownStub | ||
}); | ||
})); | ||
$.provider('hash1', $.depends(['shutdownChecker'], hashProvider)); | ||
$.provider('hash2', $.depends(['shutdownChecker'], hashProvider)); | ||
$.run(['hash1', 'hash2', '$shutdown', 'shutdownChecker']).then(function (dependencies) { | ||
_assert2.default.deepEqual(Object.keys(dependencies), ['hash1', 'hash2', '$shutdown', 'shutdownChecker']); | ||
shutdownCallPromise.then(function () { | ||
_assert2.default.deepEqual(shutdownStub.args, [[]]); | ||
shutdownResolve(); | ||
}).catch(done); | ||
return dependencies.$shutdown(); | ||
}).then(done).catch(done); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "knifecycle", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Manage your NodeJS processes's lifecycle.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -217,2 +217,3 @@ import YError from 'yerror'; | ||
servicesSequence: [], | ||
servicesShutdownsPromises: new Map(), | ||
errorsPromises: [], | ||
@@ -250,7 +251,15 @@ }; | ||
const serviceDescriptor = siloContext.servicesDescriptors.get(serviceName); | ||
let serviceShutdownPromise = siloContext.servicesShutdownsPromises.get(serviceName); | ||
if(serviceShutdownPromise) { | ||
debug('Reusing a service shutdown promise:', serviceName); | ||
return serviceShutdownPromise; | ||
} | ||
debug('Shutting down a service:', serviceName); | ||
return serviceDescriptor.shutdownProvider ? | ||
serviceShutdownPromise = serviceDescriptor.shutdownProvider ? | ||
serviceDescriptor.shutdownProvider() : | ||
Promise.resolve(); | ||
siloContext.servicesShutdownsPromises.set(serviceName, serviceShutdownPromise); | ||
return serviceShutdownPromise; | ||
}) | ||
@@ -257,0 +266,0 @@ ) |
@@ -401,4 +401,47 @@ import assert from 'assert'; | ||
it('should work with deeper multi used dependencies', (done) => { | ||
let shutdownCallResolve; | ||
let shutdownResolve; | ||
const shutdownCallPromise = new Promise((resolve) => { | ||
shutdownCallResolve = resolve; | ||
}); | ||
const shutdownStub = sinon.spy(() => { | ||
shutdownCallResolve(); | ||
return new Promise((resolve) => { | ||
shutdownResolve = resolve; | ||
}); | ||
}); | ||
$.constant('ENV', ENV); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('shutdownChecker', $.depends(['hash'], () => Promise.resolve({ | ||
servicePromise: Promise.resolve({ | ||
shutdownStub, | ||
shutdownResolve, | ||
}), | ||
shutdownProvider: shutdownStub, | ||
}))); | ||
$.provider('hash1', $.depends(['shutdownChecker'], hashProvider)); | ||
$.provider('hash2', $.depends(['shutdownChecker'], hashProvider)); | ||
$.run(['hash1', 'hash2', '$shutdown', 'shutdownChecker']) | ||
.then((dependencies) => { | ||
assert.deepEqual(Object.keys(dependencies), [ | ||
'hash1', 'hash2', '$shutdown', 'shutdownChecker', | ||
]); | ||
shutdownCallPromise.then(() => { | ||
assert.deepEqual(shutdownStub.args, [[]]); | ||
shutdownResolve(); | ||
}) | ||
.catch(done); | ||
return dependencies.$shutdown(); | ||
}) | ||
.then(done) | ||
.catch(done); | ||
}); | ||
}); | ||
}); |
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
73189
1428