iilyak commented on pull request #3481:
URL: https://github.com/apache/couchdb/pull/3481#issuecomment-810801703


   There are very few places where we need to call `acquire_context/1` and 
`release_context/1` so I am ok with proposed change. However I wanted to make 
sure you did consider a different option, which is something like the following:
   
   ```
   -module(couch_eval).
   
   -map_docs/2
   +map_docs/2,
   +with_context/2,
   +try_compile/3
   
   with_context(#{language := Language}, Fun) ->
       case acquire_context(Language) of
       try acquire_context(Language) of
           {ok, Ctx} -> Fun(Ctx)
       after
           release_context(Ctx)
       end.
       
   
   %% this would be private function
   -spec acquire_context(language()) -> {ok, context()} | {error, any()}.
   acquire_context(Language) ->
       ApiMod = get_api_mod(Language),
       {ok, Ctx} = ApiMod:acquire_context(),
       {ok, {ApiMod, Ctx}}.
   ```
   
   Then the caller would look like:
   
   ```
   -module(couch_mrview).
   
   validate(DbName, _IsDbPartitioned,  DDoc) ->
       ...
       Views =/= [] andalso couch_eval:with_context(#{language => Lang}, 
fun(Ctx) ->
            lists:foreach(fun(V) -> ValidateView(Ctx, V) end, Views)     
       end),
       ok.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to