Skip to content

Instantly share code, notes, and snippets.

View bfunc's full-sized avatar

Pavel Litkin bfunc

View GitHub Profile
@bfunc
bfunc / machine.js
Created April 11, 2021 22:56
Generated by XState Viz: https://xstate.js.org/viz
const wait = ms => new Promise(r => setTimeout(() => r(), ms));
const fetchPosts = (context, event) => {
const { q: num } = context;
console.log('> fetchPosts',num)
if (num == 5) {
return new Promise((r, reject) => reject(new Error('Oh too bad...')));
}
@bfunc
bfunc / machine.js
Created April 25, 2021 16:47
Generated by XState Viz: https://xstate.js.org/viz
const wait = ms => new Promise(r => setTimeout(() => r(), ms))
const fetchResource = async ({ url, fakeDelayMs = 0 }) => {
await wait(fakeDelayMs)
return fetch(url).then(res => res.json())
}
const constants = {
MAX_QUESTION_SCORE: 3,
MAX_RETRIES: 15,
FAILURE_DELAY: 2000,
@bfunc
bfunc / machine.js
Created July 22, 2021 08:08
Generated by XState Viz: https://xstate.js.org/viz
// The Door - state machine
const fetchMachine = Machine({
id: 'TheDoor',
initial: 'locked',
context: {},
states: {
locked:{
id:'locked',
on: { UNLOCK: 'unlocked' }
},
@bfunc
bfunc / machine.js
Created August 24, 2021 15:16
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@bfunc
bfunc / interview_test_helpers.ts
Created October 4, 2024 08:12 — forked from IlyaGershman/interview_test_helpers.ts
This is a small set of functions to help you write simple tests without frameworks
type Config = {
logPerformance?: boolean;
timeout?: number; // Timeout in milliseconds
};
function createTestRunner(initialConfig?: Config) {
let globalConfig: Config = {
logPerformance: false,
timeout: 5000,
...initialConfig,