Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:26:14+00:00 2026-06-18T11:26:14+00:00

I am building an app which can run in two modes. A sandbox mode

  • 0

I am building an app which can run in two modes. A sandbox mode and a production one.

In sandbox mode, i want to make many checks in my gen_server against the database : if table doesn’t exist then create it ; if column doesn’t exist then add it ; if column type doesn’t allow the value i want to store then change it, etc.

In production mode, if a tables does not exist or a column does not match the type of the value, it will fail and that is ok.

So, in order to avoid cumbersome code like “case State#state.is_sandbox of true -> … “,
i would like to have two different modules for my gen_server, and i would like to change the current module either in handle_call or handle_info.

Actually, i just want to go from sandbox to production, but i think if it works this way, it could work backwards.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:26:15+00:00Added an answer on June 18, 2026 at 11:26 am

    You can add module, which is a name of a module, to the state in gen_server. Then you will need 2 modules – sandbox and production that both implement the same functions (you could create a behaviour for it).

    The gen_server callbacks will call module:function which will be a function either from sandbox or production module. The module can be set in init function of the gen_server, to change it, simply add a new function(s) to the gen_server:

    use_production() ->
        gen_server:cast(production).
    
    ....
    
    handle_cast(production, State) ->
        {noreply, State#state{module = production}).
    

    The same for the sandbox module.

    An example of a gen_server’s callback with the module:

    handle_call(Msg, _From, #state{module = Module} = State) ->
        Module:function(Msq),
        {reply, ok, State}.
    

    The function must be implemented in both sandbox and production modules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im building an app which uses Sqlite DB. Users can enter their information into
I am using Rails 3, and building an app in which a user can
I have one C code app. which i was building using MS-VS2005. I had
I am building a Prism app with several modules, one of which ( MyModule
I am building an app which requires saving a form whenever user enter the
I am building an app which contains a list of addresses. This app is
I am building an app for which I need to set up cron jobs.
I'm building a Rails app which creates a bookmarklet file for each user upon
I'm building an AJAX app which animates in content dynamically. Since all links are
I am building an iphone app which allows people to update an xml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.