{"id":19774411,"url":"https://github.com/zbinlin/node-serial-async","last_synced_at":"2025-10-10T21:36:45.841Z","repository":{"id":141729873,"uuid":"61991467","full_name":"zbinlin/node-serial-async","owner":"zbinlin","description":null,"archived":false,"fork":false,"pushed_at":"2016-06-29T09:35:29.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T01:26:30.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zbinlin.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}},"created_at":"2016-06-26T14:01:15.000Z","updated_at":"2016-06-26T14:01:41.000Z","dependencies_parsed_at":"2023-06-11T02:46:43.482Z","dependency_job_id":null,"html_url":"https://github.com/zbinlin/node-serial-async","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"12e42d653a960edb405be57d9b2546e2d180e9a9"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbinlin%2Fnode-serial-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbinlin%2Fnode-serial-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbinlin%2Fnode-serial-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbinlin%2Fnode-serial-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbinlin","download_url":"https://codeload.github.com/zbinlin/node-serial-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241105155,"owners_count":19910576,"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-11-12T05:12:53.746Z","updated_at":"2025-10-10T21:36:40.806Z","avatar_url":"https://github.com/zbinlin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serial-async\n\n[![Build Status](https://img.shields.io/travis/zbinlin/node-serial-async/master.svg?style=flat-square)](https://travis-ci.org/zbinlin/node-serial-async)\n[![NPM version](https://img.shields.io/npm/v/serial-async.svg?style=flat-square)](https://www.npmjs.org/package/serial-async)\n\n\u003e Serialization async function(promise)\n\n## Example\n\n```javascript\nconst transaction = require(\".\")();\n\nconst asyncStorage = {\n    storage: {\n        foo: \"bar\",\n    },\n    get(key) {\n        return new Promise((resolve, reject) =\u003e {\n            if (key === undefined) {\n                resolve(this.storage);\n            } else {\n                resolve(this.storage[key]);\n            }\n        });\n    },\n    set(key, val) {\n        return new Promise((resolve, reject) =\u003e {\n            this.storage[key] = val;\n            resolve();\n        });\n    },\n};\n\nfunction upper() {\n    return asyncStorage.get(\"foo\").then(val =\u003e {\n        // val === \"bar\"\n        return new Promise((resolve, reject) =\u003e {\n            // looooog time\n            setTimeout(() =\u003e {\n                // if that is normal call, now asyncStorage.storage.foo is `biz`,\n                // but val still is `bar`.\n                resolve(asyncStorage.set(\"foo\", String(val).toUpperCase()));\n            }, 100);\n        });\n    });\n}\nfunction setBiz() {\n    return asyncStorage.get(\"foo\").then(val =\u003e {\n        return asyncStorage.set(\"foo\", \"biz\");\n    });\n}\n\n// normal\nPromise.all([\n    upper(),\n    setBiz(),\n]).then(() =\u003e {\n    console.log(\"normal:\", asyncStorage.storage); // result: { foo: \"BAR\" }\n});\n\n// use transaction\nPromise.all([\n    transaction(upper),\n    transaction(setBiz),\n]).then(() =\u003e {\n    console.log(\"transaction:\", asyncStorage.storage); // result: { foo: \"biz\" }\n});\n```\n\n\n## NOTE\n\n```javascript\n// You must not use the code like:\nconst foo = transaction(function () {\n    return new Promise((resolve, reject) =\u003e {\n        setTimeout(() =\u003e {\n            resolve(foo);\n        });\n    });\n});\ntransaction(function () {\n    // It will never run here\n    console.log(\"bar\");\n});\n\n// The above is equal:\nconst foo = new Promise((resolve, reject) =\u003e {\n    setTimeout(() =\u003e {\n        resolve(foo);\n    });\n});\nfoo.then(() =\u003e {\n    // It will never run here\n    console.log(\"bar\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbinlin%2Fnode-serial-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbinlin%2Fnode-serial-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbinlin%2Fnode-serial-async/lists"}