Skip to content

Commit

Permalink
feat!: Remove lazy option for server
Browse files Browse the repository at this point in the history
BREAKING: server will always try to read / pre-cache file entries on startup.
  • Loading branch information
gmaclennan committed Oct 17, 2024
1 parent 2bbf4d4 commit c863f0e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 4 additions & 9 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { noop } from './utils/misc.js'

/**
* @typedef {object} PluginOptions
* @property {boolean} [lazy=false]
* @property {string} [prefix]
* @property {string} filepath Path to styled map package (`.smp`) file
*/
Expand All @@ -34,8 +33,8 @@ function sendResource(reply, resource) {
*
* @type {FastifyPluginCallback<PluginOptions>}
*/
export default function (fastify, { lazy = false, filepath }, done) {
const deferredReader = new DeferredReader(filepath, { lazy })
export default function (fastify, { filepath }, done) {
const deferredReader = new DeferredReader(filepath)

fastify.addHook('onClose', async () => {
try {
Expand Down Expand Up @@ -94,14 +93,10 @@ class DeferredReader {

/**
* @param {string} filepath
* @param {object} opts
* @param {boolean} [opts.lazy=false]
*/
constructor(filepath, { lazy = false } = {}) {
constructor(filepath) {
this.#filepath = filepath
if (!lazy) {
this.get().catch(noop)
}
this.get().catch(noop)
}

async get() {
Expand Down
13 changes: 0 additions & 13 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,6 @@ test('server.close() closes reader', { skip: isWin() }, async () => {
assert.equal(await fdCount(filepath), 0)
})

test('server lazy', { skip: isWin() }, async () => {
const filepath = new URL('./fixtures/demotiles-z2.smp', import.meta.url)
.pathname
const fastify = createFastify()
fastify.register(createServer, { filepath, lazy: true })
await fastify.listen()
assert.equal(await fdCount(filepath), 0)
await fastify.inject({ url: '/style.json' })
assert.equal(await fdCount(filepath), 1)
await fastify.close()
assert.equal(await fdCount(filepath), 0)
})

test('server invalid filepath', async (t) => {
const filepath = 'invalid_file_path'
const fastify = createFastify()
Expand Down

0 comments on commit c863f0e

Please sign in to comment.