Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the following code intended or just due to carelessness? #464

Open
qwfy opened this issue Aug 9, 2017 · 0 comments
Open

Is the following code intended or just due to carelessness? #464

qwfy opened this issue Aug 9, 2017 · 0 comments

Comments

@qwfy
Copy link

qwfy commented Aug 9, 2017

In the file os_db.ml, there is this chunk of code:

let transaction_block db f =
  Lwt_PGOCaml.begin_work db >>= fun _ ->
  try_lwt
    lwt r = f () in    (*****A*****)
    lwt () = Lwt_PGOCaml.commit db in
    Lwt.return r
  with e ->
    lwt () = Lwt_PGOCaml.rollback db in
    Lwt.fail e

let full_transaction_block f = (*****B*****)
  Lwt_pool.use !pool (fun db -> transaction_block db (fun () -> f db))  (*****C*****)

I'm little confused, why the f at B gets wrapped to a fun () -> f db at C and passed to A?, couldn’t we just pass f at C and replace A with let r = f db?

If it's just careless writing, I think it should be corrected, it confuses beginners such as me and prevents refactoring (you know, those cases you think a chunk of code is useless, but you don't have the gut to remove them).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant