{"id":15792355,"url":"https://github.com/nfour/coroutiner","last_synced_at":"2025-06-27T18:33:51.460Z","repository":{"id":57209527,"uuid":"37888701","full_name":"nfour/coroutiner","owner":"nfour","description":"Transforms GeneratorFunctions into coroutines","archived":false,"fork":false,"pushed_at":"2015-06-23T07:40:45.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T23:07:07.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","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/nfour.png","metadata":{"files":{"readme":"readme.md","changelog":"history.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-23T00:50:39.000Z","updated_at":"2015-06-23T07:26:05.000Z","dependencies_parsed_at":"2022-09-01T07:50:42.177Z","dependency_job_id":null,"html_url":"https://github.com/nfour/coroutiner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fcoroutiner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fcoroutiner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fcoroutiner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfour%2Fcoroutiner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfour","download_url":"https://codeload.github.com/nfour/coroutiner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246523897,"owners_count":20791444,"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-04T23:01:26.291Z","updated_at":"2025-03-31T18:49:28.034Z","avatar_url":"https://github.com/nfour.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coroutiner\nA convenience transformer to turn every `GeneratorFunction` into a `Promise.coroutine`.\n\n```js\n\ncoroutiner = require('coroutiner')\n\nobj = {\n\tfn: function*() {\n\t\tyield Promise.delay(500)\n\t\treturn new Promise(function(resolve) { resolve(1000) })\n\t}\n\t\n\tnormalFn: function() { return 5 }\n}\n\ncoroutiner( obj )\n\nobj.fn().then(function(number) {\n\tnumber // returns 1000\n})\n\n\nPromise.coroutine(function*() {\n\tyield obj.fn() // returns 1000\n}\n\nobj.normalFn() // returns 5\n```\n\n### Why?\n\nInstead of calling `Promise.coroutine` on every generator function, just call coroutiner on a parent object. This allows one to build an application utilizing `yield` much more conveniently when every generator is already promisified.\n\nJust be careful what you run this over. When `prototype: true` (default) is enabled this will work on `class (){}.prototype`, `function(){}.prototype` and `{}.__proto__`, which includes instances of classes.\n\nYou can also do it recursively.\n\n```js\n// Create a new coroutiner, which also enumerates over a functions prototype\ncoroutiner = require('coroutiner')\n\nfn = function*() {}\nfn.prop = 1\n\nobj = {\n\tfn: fn\n\tanArray: [\n\t\t{\n\t\t\tfn: function*(){} // coroutined, due to { array: true }\n\t\t}\n\t]\n\tklass: class Class {\n\t\tfn: function*() {} // coroutined, due to { prototype: true }\n\t}\n}\n\n// This is run on every matched GeneratorFunction\n// Returning `false` will skip it from being transformed\nvalidatorFunction = function(key, value, parent) {\n\tif ( key.match(/idontwantyou/) ) {\n\t\treturn false // skipping\n\t}\n}\n\ncoroutiner.all(obj, validatorFunction)\n\n// Properties of GeneratorFunctions will be copied over\nobj.fn.prop // returns 1\n```\n\n### Caveats and Warnings\nCoroutiner will behave weirdly in this CoffeeScript example\n```coffee\nclass Test\n\tfn: =\u003e \n\t\t# A bound function!\n\t\tyield return\n\t\t\nclass NewTest extends Test\n\tnewFn: -\u003e yield return\n\ntest = new NewTest()\n\ncoroutiner { test, NewTest }\n\nyield test.fn() # Error, because .fn() never got coroutined before being extended\nyield test.newFn() # Works because it was defined in NewTest's prototype\nyield new NewTest().fn() # Works because the instance was created with the coroutined prototype\n```\n\n### The transformer\nMake sure `require('bluebird')` works if you aren't specifying your own transformer. Bluebird's `Promise.coroutine` is used as a transformer by default, but by creating your own coroutiner instance that can change.\n\n#### coroutiner( obj, ?validatorFn?, ?types? )\nReturned by `require('coroutiner')`.\n\nTransforms `GeneratorFunctions` within the obj with the transformer. Will also enumerate over the `fn.prototype` if prototypes are enabled.\n\nThis is not recursive.\n\n#### coroutiner.all( obj, ?validator?, ?depth?, ?types? )\nRecursively transforms properties, like `coroutiner()`.\nBe careful with this. Only run it over an object that exposes your generators. If this touches a library that expects generators then things will break.\n\n#### coroutiner.Coroutiner( options )\nCreates a new coroutiner instance.\n\n`options {Object}`\n- `validator {Function}` A default validator function\n- `transformer {Function}` A default transformer instead of `Promise.coroutine`\n- `array {Boolean} true` Whether to iterate over arrays items\n- `object {Boolean} true` Whether to iterate over object properties\n- `function {Boolean} true` Whether to iterate over function properties\n- `prototype {Boolean} true` Whether to iterate over function/object prototypes\n\nThis controls which properties are enumerated over to look for transformable properties.\n\n#### coroutiner.create( fn, ?types? )\nCreate a coroutined function and copies over its properties into a new returned function.\nThis is called by `coroutiner()` and `coroutiner.all()`\n\n#### coroutiner.types\n```\n{\n\tobject: true, function: true, array: true\n\tprototype: true, unowned: true, circular: false\n}\n```\n\n`unowned` as `false` if you only want `.hasOwnProperty` properties\n`circular` as `true` will remove cyclic recursion protection\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfour%2Fcoroutiner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfour%2Fcoroutiner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfour%2Fcoroutiner/lists"}