Internal peer package used to ensure signals emitted from stores are executed in a reliable predictable manner even as stores and subscriptions are changed.
Note: It is important that this package be installed as a peer dependency to ensure the queue is shared between store implementations
# pnpm
$ pnpm add --save-peer @crikey/stores-base-queue
# npm
$ npm add --save-peer @crikey/stores-base-queue
# yarn
$ yarn add --peer @crikey/stores-base-queue
Enqueue the provided actions using a FIFO queue. If the queue is empty, the actions will begin being called immediately until the queue is exhausted. Further actions may be added during execution which will be executed once the preceding actions are exhausted.
Example:
From ./packages/stores-base-queue/examples/store-queue.test.ts#8~21
const action_a = () => { console.log('action a') };
const action_b = () => { console.log('action b') };
enqueue_store_signals([
action_a,
action_b
]);
// > action a
// > action b
Example with nesting:
From ./packages/stores-base-queue/examples/store-queue.test.ts#32~54
enqueue_store_signals([
() => { console.log("action 1") },
() => {
console.log("action 2");
enqueue_store_signals([
() => { console.log("action 5") },
() => { console.log("action 6") }
]);
console.log("action 3");
},
() => { console.log("action 4") },
]);
// > action 1
// > action 2
// > action 3
// > action 4
// > action 5
// > action 6
Example Exception Handling:
From ./packages/stores-base-queue/examples/store-queue.test.ts#70~94
const original_runner = set_store_runner(create_store_runner_log_errors(console.error));
try {
enqueue_store_signals([
() => {
throw new Error('error 1');
},
() => {
throw new Error('error 2');
},
() => {
throw new Error('error 3');
}
]);
console.log('done.');
// > Error: error 1
// > Error: error 2
// > Error: error 3
// > done.
} finally {
set_store_runner(original_runner);
}
Callback used to log errors
Wrapper used to call actions and handler any possible errors
Enqueue the provided actions using a FIFO queue. If the queue is empty, the actions will begin being called immediately until the queue is exhausted. Further actions may be added during execution which will be executed once the preceding actions are exhausted.
Example:
From ./packages/stores-base-queue/examples/store-queue.test.ts#8~21
const action_a = () => { console.log('action a') };
const action_b = () => { console.log('action b') };
enqueue_store_signals([
action_a,
action_b
]);
// > action a
// > action b
Example with nesting:
From ./packages/stores-base-queue/examples/store-queue.test.ts#32~54
enqueue_store_signals([
() => { console.log("action 1") },
() => {
console.log("action 2");
enqueue_store_signals([
() => { console.log("action 5") },
() => { console.log("action 6") }
]);
console.log("action 3");
},
() => { console.log("action 4") },
]);
// > action 1
// > action 2
// > action 3
// > action 4
// > action 5
// > action 6
array of actions to enqueue
Returns the active store_runner
Sets the active store_runner
new store_runner
previous store_runner
The active store runner used while executing actions queued with enqueue_store_signals
The store runner is primarily used for handling unhandled exceptions thrown by actions.
Example:
From ./packages/stores-base-queue/examples/store-queue.test.ts#70~94
const original_runner = set_store_runner(create_store_runner_log_errors(console.error));
try {
enqueue_store_signals([
() => {
throw new Error('error 1');
},
() => {
throw new Error('error 2');
},
() => {
throw new Error('error 3');
}
]);
console.log('done.');
// > Error: error 1
// > Error: error 2
// > Error: error 3
// > done.
} finally {
set_store_runner(original_runner);
}
returns a StoreRunner which logs exceptions to logger and swallows the exceptions.
function called with the given exception
returns a StoreRunner which logs exceptions to logger and swallows the exceptions.
Swallow exceptions thrown by action
Do not handle exceptions thrown by action
Generated using TypeDoc
Generic action.