queueProcessor
queueProcessor
takes an observable array, observes it and calls processor
once for each item added to the observable array, optionally debouncing the action.
Parameters
observableArray
(Array<T>
): observable array instance to trackprocessor
debounce
(number
): debounce time in ms. With debounce0
, the processor will run synchronously (optional. default:0
)
Returns
IDisposer
: stops the processor
Examples
const pendingNotifications = observable([])
const stop = queueProcessor(pendingNotifications, msg => {
// show Desktop notification
new Notification(msg);
})
// usage:
pendingNotifications.push("test!")