{"action":"closed","issue":{"url":"https://api.github.com/repos/fshost/api-chain/issues/2","labels_url":"https://api.github.com/repos/fshost/api-chain/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/fshost/api-chain/issues/2/comments","events_url":"https://api.github.com/repos/fshost/api-chain/issues/2/events","html_url":"https://github.com/fshost/api-chain/issues/2","id":57648923,"number":2,"title":"calling method from another method","user":{"login":"jandrieu","id":186831,"avatar_url":"https://avatars.githubusercontent.com/u/186831?v=3","gravatar_id":"","url":"https://api.github.com/users/jandrieu","html_url":"https://github.com/jandrieu","followers_url":"https://api.github.com/users/jandrieu/followers","following_url":"https://api.github.com/users/jandrieu/following{/other_user}","gists_url":"https://api.github.com/users/jandrieu/gists{/gist_id}","starred_url":"https://api.github.com/users/jandrieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jandrieu/subscriptions","organizations_url":"https://api.github.com/users/jandrieu/orgs","repos_url":"https://api.github.com/users/jandrieu/repos","events_url":"https://api.github.com/users/jandrieu/events{/privacy}","received_events_url":"https://api.github.com/users/jandrieu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-13T20:19:57Z","updated_at":"2015-04-27T06:34:09Z","closed_at":"2015-04-27T06:34:09Z","body":"How do you call a method from another method so that it acts as a subchain?\r\n\r\nI thought I had this working, but then I restructured my code and can't get it working again.\r\n\r\nHere's a simplified case, where I would expect the printouts to be A, B, C, D, but they are A, B, D, C.\r\n\r\nThe tricky part is that the second method in the chain depends on an asynchronous callback. And that's where it comes apart.\r\n\r\n```javascript\r\n#!/usr/bin/env node\r\n\r\nvar api = require('api-chain');\r\n\r\nvar tester = api.create({\r\n  A: A,\r\n  B: B,\r\n  C: C,\r\n  D: D,\r\n});\r\n\r\nfunction A(next) {\r\n  console.log('A');\r\n  this\r\n    .B()\r\n    .C()\r\n  next();\r\n}\r\n\r\nfunction B(next) {\r\n  setTimeout(function(){\r\n    console.log('B');\u0007\r\n    next();\r\n  },5000);\r\n}\r\n\r\nfunction C(next) {\r\n  console.log('C');\r\n  next();\r\n}\r\n\r\nfunction D(next) {\r\n  console.log('D');\r\n  next();\r\n}\r\n\r\ntester\r\n  .A()\r\n  .D()\r\n```"}}