Registry / testing / deferred-method

deferred-method

JSON →
library1.0.1jsnpmunverified

deferred-method v1.0.1 is a lightweight utility for queueing method calls on an object until a 'ready' condition is met. It listens for a 'ready' event by default, buffering invocations and replaying them in order once the object is ready. Commonly used with async resources like database connections or message queues. Simple API: only one function and minimal overhead. Last updated in 2020, stable with no new releases expected.

npm install deferred-method
INSTALL
IMPORT
SIG · DEFERRED-METHOD
D
deferred-method
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import deferred from 'deferred-method'
const deferred = require('deferred-method');
CommonJS require works too, but ESM import is valid with bundlers supporting CommonJS interop.
default
const deferred = require('deferred-method')
Package is CommonJS; no named exports.

Demonstrates queuing method calls before ready and replaying after ready event.

const deferred = require('deferred-method'); const obj = { ready: false, save: function(data) { console.log('Saving', data); }, emitReady() { this.ready = true; this.emit('ready'); } }; const EventEmitter = require('events'); Object.setPrototypeOf(obj, EventEmitter.prototype); deferred(obj, 'save'); obj.save('first'); obj.save('second'); obj.emitReady(); obj.save('third');
Debug
Known issues
gotchaThe deferred method must be an existing function on the object; otherwise it throws.
fix
Ensure the method is defined before calling deferred().
affects: *
gotchaDefault ready event is 'ready'. If the object uses a different event name, provide a custom ready function.
fix
Pass a custom ready listener as third argument, e.g., deferred(obj, 'method', obj.once.bind(obj, 'customEvent')).
affects: *
gotchaQueued calls are replayed synchronously after ready; they will not be interleaved with subsequent calls occurring after ready.
fix
After ready, calls execute immediately in order; no queuing after ready.
affects: *
Errors
Common errors & fixes
TypeError: deferred is not a function
Using incorrect import syntax (e.g., import { deferred } from 'deferred-method').
fix
Use default import: import deferred from 'deferred-method' or const deferred = require('deferred-method').
TypeError: obj[name] is not a function
The specified method does not exist on the object.
fix
Ensure the method exists before calling deferred(obj, 'methodName').
TypeError: Cannot read properties of undefined (reading 'on')
The object does not inherit from EventEmitter or does not have an 'on' method for the default ready listener.
fix
Provide a custom ready function that triggers when the object is ready.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
deferred-method — npm install deferred-method · libregistry