{"action":"created","issue":{"url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/1","labels_url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/1/comments","events_url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/1/events","html_url":"https://github.com/gariepyalex/bankaccount/pull/1","id":120916391,"number":1,"title":"Fixes a crash when there are pending transactions","user":{"login":"jni-","id":541961,"avatar_url":"https://avatars.githubusercontent.com/u/541961?v=3","gravatar_id":"","url":"https://api.github.com/users/jni-","html_url":"https://github.com/jni-","followers_url":"https://api.github.com/users/jni-/followers","following_url":"https://api.github.com/users/jni-/following{/other_user}","gists_url":"https://api.github.com/users/jni-/gists{/gist_id}","starred_url":"https://api.github.com/users/jni-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jni-/subscriptions","organizations_url":"https://api.github.com/users/jni-/orgs","repos_url":"https://api.github.com/users/jni-/repos","events_url":"https://api.github.com/users/jni-/events{/privacy}","received_events_url":"https://api.github.com/users/jni-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-08T02:29:56Z","updated_at":"2015-12-08T02:48:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/gariepyalex/bankaccount/pulls/1","html_url":"https://github.com/gariepyalex/bankaccount/pull/1","diff_url":"https://github.com/gariepyalex/bankaccount/pull/1.diff","patch_url":"https://github.com/gariepyalex/bankaccount/pull/1.patch"},"body":"When pending transactions were detected, the thing crashed.\r\n\r\nMy clojure is very rusty so I might have gotten this wrong, but this is\r\nwhat I gather from it :\r\n\r\n * Adding to the pending-tx atom was creating duplicates, because it was\r\n   running with (swap! pending-tx conj @pending-tx new-tx), which conj's\r\n   pending-tx with itself.\r\n * The do-pending-tx method was not derefencing the atom when applying\r\n   it, which cause the error \"java.lang.ClassCastException:\r\n   bankaccount.core$do_pending_transactions$fn__65 cannot be cast to\r\n   clojure.lang.Atom\"."},"comment":{"url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/comments/162741967","html_url":"https://github.com/gariepyalex/bankaccount/pull/1#issuecomment-162741967","issue_url":"https://api.github.com/repos/gariepyalex/bankaccount/issues/1","id":162741967,"user":{"login":"gariepyalex","id":6105461,"avatar_url":"https://avatars.githubusercontent.com/u/6105461?v=3","gravatar_id":"","url":"https://api.github.com/users/gariepyalex","html_url":"https://github.com/gariepyalex","followers_url":"https://api.github.com/users/gariepyalex/followers","following_url":"https://api.github.com/users/gariepyalex/following{/other_user}","gists_url":"https://api.github.com/users/gariepyalex/gists{/gist_id}","starred_url":"https://api.github.com/users/gariepyalex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gariepyalex/subscriptions","organizations_url":"https://api.github.com/users/gariepyalex/orgs","repos_url":"https://api.github.com/users/gariepyalex/repos","events_url":"https://api.github.com/users/gariepyalex/events{/privacy}","received_events_url":"https://api.github.com/users/gariepyalex/received_events","type":"User","site_admin":false},"created_at":"2015-12-08T02:48:47Z","updated_at":"2015-12-08T02:48:47Z","body":"You are right your version is more readable.\r\n\r\nI did mine like this to remove atomically the first element of the pending-transaction atom and get that return (in the current-transaction atom). It is over-engineering in that case because the while loop runs sequentially.\r\n\r\nWe could imagine a case in your version where another thread would modify the pending-transaction atom while the current thread is on line https://github.com/jni-/bankaccount/blob/7ab3064d8b75a639fa0be4095cef31f583a5343e/src/bankaccount/core.clj#L66. That could result on a pending-transaction being done twice."}}