{"id":16847541,"url":"https://github.com/fabiosantoscode/persistent-lang","last_synced_at":"2025-07-11T03:35:31.423Z","repository":{"id":146300933,"uuid":"443201708","full_name":"fabiosantoscode/persistent-lang","owner":"fabiosantoscode","description":"A language whose state can be persisted to disk, through the use of a fully-JSON state object","archived":false,"fork":false,"pushed_at":"2022-02-10T21:56:47.000Z","size":294,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T07:17:20.996Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabiosantoscode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-30T22:54:14.000Z","updated_at":"2022-01-17T09:03:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"11f0629d-15d3-47c0-bce6-59d488f3e982","html_url":"https://github.com/fabiosantoscode/persistent-lang","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fabiosantoscode/persistent-lang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fpersistent-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fpersistent-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fpersistent-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fpersistent-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiosantoscode","download_url":"https://codeload.github.com/fabiosantoscode/persistent-lang/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fpersistent-lang/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264721887,"owners_count":23654019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T13:08:18.232Z","updated_at":"2025-07-11T03:35:31.385Z","avatar_url":"https://github.com/fabiosantoscode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# persistent-lang\n\nA language that has an extreme capacity to chill out. You can save your program's state to disk or your store of choice. And you can \"run\" millions of concurrent processes for cheap, since you can move them to any persistent storage of your choice.\n\nYou might use this to control a process that is run by multiple machines and can last multiple days or months, without worrying about keeping a machine running for that purpose.\n\nHere are some examples that don't currently work because this is WIP AF:\n\n# Examples\n\nHere's a program that controls a subscription to a paid membership\n\n```javascript\nimport { createProgram } from 'persistent-lang'\nimport { saveStateToDisk, loadStateFromDisk } from './your-stuff.js'\nimport {\n  charge,\n  setSubscriptionActive,\n  SUBSCRIPTION_DURATION_MS,\n  GRACE_PERIOD_MS,\n} from './your-subscription-management.js'\n\nconst machine = createProgram`\n  (if (== (chargeCustomer customerId) \"charge-failed\")\n    (exit \"charge-failed\"))\n\n  (${setSubscriptionActive} customerId true)\n\n  (while true\n    (wait ${SUBSCRIPTION_DURATION_MS})\n    (if cancelled\n      (exit \"cancelled\"))\n    (if (== (chargeCustomer customerId) \"charge-failed\")\n      (gracePeriod customerId)))\n\n  (fn gracePeriod [customerId]\n    # Give the customer a grace period, before disabling the customer's\n    # subscription and giving up\n    (set emailResult\n      (race\n        (chargeCustomer customerId)\n        (wait ${GRACE_PERIOD_MS} \"timed-out\")))\n\n    (if (== emailResult \"timed-out\")\n      (do\n        (${setSubscriptionActive} customerId false)\n        (exit \"charge-failed\"))))\n\n  (fn chargeCustomer []\n    (yield \"chargeCustomer\"))\n`({\n  yieldPoints: {\n    async chargeCustomer(state) {\n      const customerId = state.processId\n      await charge(customerId)\n    },\n  },\n  async loadState(processId) {\n    return await loadStateFromDisk(processId)\n  },\n  async saveState(processId, newState) {\n    return await saveStateToDisk(processId, newState)\n  },\n  async handleExit(processId, exitArg) {\n    // Send a sad e-mail to the customer\n  },\n})\n\nexport function createSubscription(customerId) {\n  await machine.spawnProcess({\n    processId: customerId,\n    variables: { customerId, cancelled: false },\n  })\n}\n\nexport async function handleChargeSuccessful(customerId) {\n  const state = await machine.loadState(customerId)\n  if (state.yielded !== 'chargeCustomer') {\n    // We weren't expecting a charge, what's up?\n    throw Refund()\n  }\n\n  // Continue running\n  await state.satisfyYield()\n}\n\nexport async function handleCancellation(customerId, cancelled = true) {\n  const state = await machine.loadState(customerId)\n  await state.changeGlobalVariable(state, 'cancelled', cancelled)\n}\n\n// TODO explain how waiting works, I don't know how yet but Redis will likely be involved\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fpersistent-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiosantoscode%2Fpersistent-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fpersistent-lang/lists"}