{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/243","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/243/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/243/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/243/events","html_url":"https://github.com/petkaantonov/bluebird/pull/243","id":36502478,"number":243,"title":"refactor the Promises$reduce state machine","user":{"login":"cantremember","id":50385,"avatar_url":"https://avatars.githubusercontent.com/u/50385?v=3","gravatar_id":"","url":"https://api.github.com/users/cantremember","html_url":"https://github.com/cantremember","followers_url":"https://api.github.com/users/cantremember/followers","following_url":"https://api.github.com/users/cantremember/following{/other_user}","gists_url":"https://api.github.com/users/cantremember/gists{/gist_id}","starred_url":"https://api.github.com/users/cantremember/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cantremember/subscriptions","organizations_url":"https://api.github.com/users/cantremember/orgs","repos_url":"https://api.github.com/users/cantremember/repos","events_url":"https://api.github.com/users/cantremember/events{/privacy}","received_events_url":"https://api.github.com/users/cantremember/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2014-06-25T17:12:26Z","updated_at":"2015-02-18T01:35:01Z","closed_at":"2014-07-07T10:08:07Z","pull_request":{"url":"https://api.github.com/repos/petkaantonov/bluebird/pulls/243","html_url":"https://github.com/petkaantonov/bluebird/pull/243","diff_url":"https://github.com/petkaantonov/bluebird/pull/243.diff","patch_url":"https://github.com/petkaantonov/bluebird/pull/243.patch"},"body":"I experienced failures while attempting to use `Promise.reduce` under a variety of conditions, many of which involved staggered asynchronous resolution of\r\n- the accumulator / \"initialValue\"\r\n- the \"0th value\", when no \"initialValue\" was provided\r\n- values in the Array to be reduced\r\n- the reduce iterator\r\n\r\nSignificant attempts were made to patch the existing `Promise$reduce` implementation, but once a Test Suite considering a matrix of asynchronous permutations was implemented, I concluded that the existing code was un-patchable :(\r\n\r\nThe most pragmatic course of action was to refactor its state machine logic so that it could better separate the multiple phases of the reduction process\r\n\r\n1. inbound flow of resolved values for the \"initialValue\" / \"0th value\" (Phase 1)\r\n2. inbound flow of resolved values from the Array to be reduced (Phase 1)\r\n3. inception of, and incremental reduction of, the Array values (Phase 2)\r\n4. detecting completion\r\n\r\nThe previous implementation did all of these things, but a thorough Test Suite revealed that there was too tight of a coupling between the inbound flow and the incremental reduction processes. This became most evident when the values in the Array resolved at staggered intervals and the reduce iterator did so as well.\r\n\r\nI understand that this is a *considerable rewrite* and I am eager to collaborate with you to bring it up-to-spec with your current module design via your code review process.\r\n\r\nThe Test Suite for `Promise$reduce` has grown significantly, and it is possible that some cases are redundant or unnecessary.  I wanted to be absolutely sure of the new code's stability, especially in the light of the multi-phase state machine and its edge conditions. I left the existing Test Cases in place, though they may now be redundant.\r\n\r\nThank you for all the work you've put into the library.  It is a shining beacon of the Promises specification.\r\n"},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/74794418","html_url":"https://github.com/petkaantonov/bluebird/pull/243#issuecomment-74794418","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/243","id":74794418,"user":{"login":"RichAyotte","id":294987,"avatar_url":"https://avatars.githubusercontent.com/u/294987?v=3","gravatar_id":"","url":"https://api.github.com/users/RichAyotte","html_url":"https://github.com/RichAyotte","followers_url":"https://api.github.com/users/RichAyotte/followers","following_url":"https://api.github.com/users/RichAyotte/following{/other_user}","gists_url":"https://api.github.com/users/RichAyotte/gists{/gist_id}","starred_url":"https://api.github.com/users/RichAyotte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RichAyotte/subscriptions","organizations_url":"https://api.github.com/users/RichAyotte/orgs","repos_url":"https://api.github.com/users/RichAyotte/repos","events_url":"https://api.github.com/users/RichAyotte/events{/privacy}","received_events_url":"https://api.github.com/users/RichAyotte/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T01:35:01Z","updated_at":"2015-02-18T01:35:01Z","body":"I can confirm that the 0th index is skipped. Not sure if it was caused by this implementation. Tested in 2.9.9."}}