Merge pull request #1835 from strongloop/feat/datasource-stop
feat: implement DataSource.stop()
This commit is contained in:
commit
74c6776575
|
@ -2220,6 +2220,14 @@ DataSource.prototype.disconnect = function disconnect(cb) {
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias for `disconnect` to make the datasource a LB4 life-cycle observer.
|
||||||
|
* Please note that we are intentionally not providing a `start` method,
|
||||||
|
* because the logic for establishing connection(s) is more complex
|
||||||
|
* and usually started immediately from the datasoure constructor.
|
||||||
|
*/
|
||||||
|
DataSource.prototype.stop = DataSource.prototype.disconnect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the model from Master.
|
* Copy the model from Master.
|
||||||
* @param {Function} Master The model constructor
|
* @param {Function} Master The model constructor
|
||||||
|
|
|
@ -330,6 +330,31 @@ describe('DataSource', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('provides stop() API calling disconnect', function(done) {
|
||||||
|
const mockConnector = {
|
||||||
|
name: 'loopback-connector-mock',
|
||||||
|
initialize: function(ds, cb) {
|
||||||
|
ds.connector = mockConnector;
|
||||||
|
process.nextTick(function() {
|
||||||
|
cb(null);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataSource = new DataSource(mockConnector);
|
||||||
|
dataSource.on('connected', function() {
|
||||||
|
// DataSource is now connected
|
||||||
|
// connected: true, connecting: false
|
||||||
|
dataSource.connected.should.be.true();
|
||||||
|
dataSource.connecting.should.be.false();
|
||||||
|
|
||||||
|
dataSource.stop(() => {
|
||||||
|
dataSource.connected.should.be.false();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('deleteModelByName()', () => {
|
describe('deleteModelByName()', () => {
|
||||||
it('removes the model from ModelBuilder registry', () => {
|
it('removes the model from ModelBuilder registry', () => {
|
||||||
const ds = new DataSource('ds', {connector: 'memory'});
|
const ds = new DataSource('ds', {connector: 'memory'});
|
||||||
|
|
|
@ -287,6 +287,9 @@ export declare class DataSource extends EventEmitter {
|
||||||
// legacy callback style
|
// legacy callback style
|
||||||
disconnect(callback: Callback): void;
|
disconnect(callback: Callback): void;
|
||||||
|
|
||||||
|
// Only promise variant, callback is intentionally not described.
|
||||||
|
stop(): Promise<void>;
|
||||||
|
|
||||||
ping(): Promise<void>;
|
ping(): Promise<void>;
|
||||||
// legacy callback style
|
// legacy callback style
|
||||||
ping(callback: Callback): void;
|
ping(callback: Callback): void;
|
||||||
|
|
Loading…
Reference in New Issue