diff --git a/backend.js b/backend.js index d0822bd..b8f4a45 100644 --- a/backend.js +++ b/backend.js @@ -164,3 +164,12 @@ Backend.prototype.getTile = function(z, x, y, callback) { }; }; +Backend.prototype.close = function(callback) { + if (!this._source) return callback(new Error('Tilesource not loaded')); + + if (typeof this._source.close === 'function') { + return this._source.close(callback); + } + + return callback(null); +}; diff --git a/index.js b/index.js index 36b3f90..9e2ec62 100644 --- a/index.js +++ b/index.js @@ -80,7 +80,7 @@ Vector.prototype.open = function(callback) { }; Vector.prototype.close = function(callback) { - return callback(); + return this._backend.close(callback); }; // Allows in-place update of XML/backends. diff --git a/test/backend.js b/test/backend.js index 51f3b31..c8c26a5 100644 --- a/test/backend.js +++ b/test/backend.js @@ -168,6 +168,15 @@ tilelive.protocols['test:'] = Testsource; }); }); }); + test('close is called on source', function(t) { + var testsource = new Testsource('a'); + new Backend({ source:testsource }, function(err, backend) { + backend.close(function(err) { + t.equal(testsource.closeCalled, true); + t.end(); + }); + }); + }); function replacer(key, value) { if (key === 'raster') { diff --git a/test/test.js b/test/test.js index 3c6066a..c125521 100644 --- a/test/test.js +++ b/test/test.js @@ -301,3 +301,11 @@ test('diff scale => diff ETags', function(t) { t.end(); }); +test('source should be closed', function(t) { + new Vector({ source:'test:///a', xml: xml.a }, function(err, source) { + source.close(function(err) { + t.equal(source._backend._source.closeCalled, true); + t.end(); + }); + }); +}); diff --git a/test/testsource.js b/test/testsource.js index 5eb77c4..53697b1 100644 --- a/test/testsource.js +++ b/test/testsource.js @@ -138,6 +138,7 @@ function Testsource(uri, callback) { vector_layers: infos[uri].vector_layers }; this.stats = {}; + this.closeCalled = false; return callback && callback(null, this); }; @@ -168,3 +169,8 @@ Testsource.prototype.getTile = function(z,x,y,callback) { Testsource.prototype.getInfo = function(callback) { return callback(null, this.data); }; + +Testsource.prototype.close = function(callback) { + this.closeCalled = true; + return callback(null); +};