Fixed-step work without overlapping ticks
Documentation for Redweb 0.13.3. Install that exact version when following these examples.
FixedStepService compensates for scheduler drift, bounds catch-up, contains async failures, and reports lag that was deliberately dropped.
This pattern demonstrates one API area. Application-specific names, credentials, assets, and policies may need to be supplied. Complete starter recipes include all required application files.
const { FixedStepService, SocketRoute } = require('redweb')
class Simulation extends FixedStepService {
constructor() {
super('simulation', 50, 3, 250)
}
async onTick(stepMs, tick) {
await authoritativeGame.update(stepMs, tick)
}
onLagDropped(milliseconds) {
console.warn('Simulation lag discarded', { milliseconds })
}
}
class SimulationRoute extends SocketRoute {
constructor() {
super({
path: '/simulation',
handlers: [InputHandler],
services: [Simulation],
})
}
}Notes and boundaries
- The active async tick must finish before another begins.
- maxCatchUpTicks prevents a spiral of death.
- maxRetainedLagMs bounds remembered delay.