{"id":21326256,"url":"https://github.com/masylum/funk","last_synced_at":"2026-03-02T01:33:17.772Z","repository":{"id":1103096,"uuid":"967206","full_name":"masylum/funk","owner":"masylum","description":"Asynchronous functions made funky!","archived":false,"fork":false,"pushed_at":"2011-09-08T18:08:30.000Z","size":122,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-11T03:26:20.678Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://masylum.github.com/funk/","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/masylum.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}},"created_at":"2010-10-06T18:29:22.000Z","updated_at":"2022-04-23T12:12:21.000Z","dependencies_parsed_at":"2022-08-16T12:00:49.442Z","dependency_job_id":null,"html_url":"https://github.com/masylum/funk","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/masylum%2Ffunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Ffunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Ffunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Ffunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masylum","download_url":"https://codeload.github.com/masylum/funk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225802658,"owners_count":17526452,"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-21T21:08:56.592Z","updated_at":"2026-03-02T01:33:12.734Z","avatar_url":"https://github.com/masylum.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"     ,dPYb,                           ,dPYb,\n     IP'`Yb                           IP'`Yb\n     I8  8I                           I8  8I\n     I8  8'                           I8  8bgg,\n     I8 dP  gg      gg   ,ggg,,ggg,   I8 dP\" \"8\n     I8dP   I8      8I  ,8\" \"8P\" \"8,  I8d8bggP\"\n     I8P    I8,    ,8I  I8   8I   8I  I8P' \"Yb,\n    ,d8b,_ ,d8b,  ,d8b,,dP   8I   Yb,,d8    `Yb,\n    PI8\"8888P'\"Y88P\"`Y88P'   8I   `Y888P      Y8\n     I8 `8,\n     I8  `8,\n     I8   8I\n     I8   8I\n     I8, ,8'\n      \"Y8P'\n\n\nAsynchronous functions made funky!\n\n## What the funk?\n\nFunk is a little module that helps you with the `serial` and `parallel` asynchronous pattern.\n\n## Instalation\n\n``` bash\nnpm install funk\n```\n\n## API\n\n**funk** usage is really simple. You don't need to learn any DSL or weird hacks,\njust wrap your callbacks and let the groove do the rest.\n\n### Constructor (pattern) -\u003e Funk\n\nAccepts a string that can be either `parallel` or `serial`, depending on the pattern you want to implement.\n\n``` javascript\nvar funk = require('funk')('serial');\n```\n\n### set (name, value) -\u003e undefined\n\nSave results that will then be recovered on the `run` callback.\n\n``` javascript\nvar funk = require('funk')('serial');\n\nsetTimeout(funk.add(function () {\n  funk.set('foo', 'bar');\n}, 100);\n\nfunk.run(function () {\n  assert.equals(this.foo, 'bar');\n});\n```\n\n### get (name) -\u003e *\n\nRetrieve results previously saved.\n\n``` javascript\nvar funk = require('funk')('serial');\n\nsetTimeout(funk.add(function () {\n  funk.set('foo', 'bar');\n}, 100);\n\nfunk.run(function () {\n  assert.equals(funk.get('foo'), 'bar');\n});\n```\n\n### add (function) -\u003e Function\n\nAdds a callback to be executed either in `parallel` or `serial`.\n\n``` javascript\nvar funk = require('funk')('parallel');\n\nsetTimeout(funk.add(function () {\n  funk.set('foo', 'bar');\n}, 200);\n\nsetTimeout(funk.add(function () {\n  funk.set('bar', 'foo');\n}, 100);\n\nfunk.run(function () {\n  assert.equals(funk.get('foo'), 'bar');\n  assert.equals(funk.get('bar'), 'foo');\n});\n```\n\n### nothing () -\u003e Function\n\nAdds the callback to funk and does nothing with the result\n\n``` javascript\nvar funk = require('funk')('parallel');\n\nsetTimeout(funk.nothing());\nsetTimeout(funk.nothing());\n\nfunk.run(function () {\n  // both setTimeout are called\n});\n```\n\n### result (name, value) -\u003e Function\n\nAdds the callback to funk and sets the value.\n\n``` javascript\nvar funk = require('funk')('parallel');\n\nfs.readFile(\"./foo.txt\", 'utf-8', funk.result('file1'));\nfs.readFile(\"./bar.txt\", 'utf-8', funk.result('file2'));\n\nfunk.run(function () {\n  assert.equal(this.file1, 'foo\\n');\n  assert.equal(this.file2, 'bar\\n');\n});\n```\n\n### result (callback, onError) -\u003e undefined\n\nWill run all the added functions in `serial` or `parallel` and call _callback_ when all are done.\n`this` holds all the results setted with `set` and the `errors`.\n\nIf a `onError` callback is implemented it will be called only on getting the first error, ignorign the following requests.\n\n``` javascript\n// serial example without declaring `onError` callback\nvar funk = require('./../')('serial'),\n    order = 0;\n\nfunk.name = 'fleiba';\nfunk.results = [];\n\nsetTimeout(funk.add(function () {\n  order += 1;\n  funk.set('order_first', order);\n}), 200);\n\nfs.readFile(__dirname + \"/data/doo.txt\", 'utf-8', funk.add(function () {\n  order += 1;\n  funk.set('order_foo', order);\n}));\n\nfs.readFile(__dirname + \"/data/gar.txt\", 'utf-8', funk.add(function () {\n  order += 1;\n  funk.set('order_bar', order);\n}));\n\nfunk.run(function () {\n  assert.equal(this.order_first, 1);\n  assert.equal(this.order_foo, 2);\n  assert.equal(this.order_bar, 3);\n  assert.equal(this.errors.length, 2); // none of the 2 files exists\n  done();\n});\n```\n\n## Tests\n\n_funk_ is fully tested using [testosterone](https://github.com/masylum/testosterone).\n\nIn order to run the tests type:\n\n``` bash\nmake\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasylum%2Ffunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasylum%2Ffunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasylum%2Ffunk/lists"}