{"id":17856864,"url":"https://github.com/akamaozu/cjs-yield","last_synced_at":"2025-06-11T21:39:51.808Z","repository":{"id":57141318,"uuid":"156084167","full_name":"Akamaozu/cjs-yield","owner":"Akamaozu","description":"Don't Start Function Until Current Callstack Ends","archived":false,"fork":false,"pushed_at":"2019-01-03T04:24:39.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T04:08:56.381Z","etag":null,"topics":["async","concurrency","cooperative","non-blocking","yield"],"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/Akamaozu.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":"2018-11-04T13:19:15.000Z","updated_at":"2019-01-03T16:58:18.000Z","dependencies_parsed_at":"2022-09-19T07:02:09.146Z","dependency_job_id":null,"html_url":"https://github.com/Akamaozu/cjs-yield","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/Akamaozu%2Fcjs-yield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akamaozu%2Fcjs-yield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akamaozu%2Fcjs-yield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akamaozu%2Fcjs-yield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Akamaozu","download_url":"https://codeload.github.com/Akamaozu/cjs-yield/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246866056,"owners_count":20846497,"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":["async","concurrency","cooperative","non-blocking","yield"],"created_at":"2024-10-28T03:10:13.978Z","updated_at":"2025-04-02T18:20:47.587Z","avatar_url":"https://github.com/Akamaozu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yield\n===\n[![npm version](https://badge.fury.io/js/cjs-yield.svg)](https://badge.fury.io/js/cjs-yield) [![Build Status](https://travis-ci.org/Akamaozu/cjs-yield.svg?branch=master)](https://travis-ci.org/Akamaozu/cjs-yield) [![Coverage Status](https://coveralls.io/repos/github/Akamaozu/cjs-yield/badge.svg?branch=master)](https://coveralls.io/github/Akamaozu/cjs-yield?branch=master)\n\nDon't Start Function Until Current [Callstack](https://www.youtube.com/watch?v=8aGhZQkoFbQ\u0026feature=youtu.be\u0026t=256) Ends\n---\n\n### Install\n\n```\nnpm install --save cjs-yield\n```\n\n### How It Works\n\n#### Call Function Normally\n\n```js\n  say_hi();\n  console.log( 'callstack ends' );\n\n  // output\n  // \u003e Hi!\n  // \u003e callstack ends\n```\n\n#### Yield Function Call\n\n```js\n  var _yield = require( 'cjs-yield' );\n\n  _yield( say_hi );\n  console.log( 'callstack ends' );\n\n  // output\n  // \u003e callstack ends\n  // \u003e Hi!\n```\n\n#### Pass Yielded Function Arguments\n\n```js\n  _yield( say_hi, 'Dr. Nick' );\n  console.log( 'callstack ends' );\n\n  // output\n  // \u003e callstack ends\n  // \u003e Hi Dr. Nick!\n```\n\n```js\n  _yield( say_hi, 'Archie', 'the Drells' );\n  console.log( 'callstack ends' );\n\n  // output\n  // \u003e callstack ends\n  // \u003e Hi Archie and the Drells!\n```\n\n```js\n  _yield( say_hi, 'Ed', 'Edd', 'Eddy' );\n  console.log( 'callstack ends' );\n\n  // output\n  // \u003e callstack ends\n  // \u003e Hi Ed, Edd and Eddy!\n```\n\n### Gotchas\n\n#### 1. Yield DOES NOT work with functions that internally use `this`\n\nInternally, yield uses `setTimeout.apply` to yield a given function, while making it easy to pass arguments to it. To make the API as simple and as pleasant as posible, `setTimeout.apply` uses null as its default context. This is fine unless the function use `this` keyword internally. Even if you avoid writing functions that use `this`, you can't escape it since many native JavaScript array methods like `Array.push` use it.\n\nTo yield a function that uses `this`, put the troublesome function into a function that doesn't use `this` and pass that new function to yield.\n\nEg.\n\n```js\n  var heroes = [];\n  _yield( heroes.push, 'Batman' );\n  console.log( 'callstack ends' );\n\n  // \u003e callstack ends\n  // \u003e heroes=[]\n```\n\nvs\n\n```js\n  var heroes = [];\n  _yield( add_hero, 'Batman' );\n  console.log( 'callstack ends' );\n\n  // \u003e callstack ends\n  // \u003e heroes=[ 'Batman' ]\n\n  function add_hero( name ){\n    heroes.push( name );\n  }\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamaozu%2Fcjs-yield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakamaozu%2Fcjs-yield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamaozu%2Fcjs-yield/lists"}