title: Erlang stop gen_server
body: <p>I have gen_server:</p>
  
  <pre><code>start(UserName) -&gt;
      case gen_server:start({global, UserName}, player, [], []) of
      {ok, _} -&gt;
          io:format("Player: " ++ UserName ++ " started");
      {error, Error} -&gt;
          Error
      end
      ...
  </code></pre>
  
  <p>Now i want to write function to stop this gen server. I have:</p>
  
  <pre><code>stop(UserName) -&gt;
      gen_server:cast(UserName, stop).
  
  handle_cast(stop, State) -&gt;
      {stop, normal, State};
  handle_cast(_Msg, State) -&gt;
      {noreply, State}.
  </code></pre>
  
  <p>I run it:</p>
  
  <pre><code>start("shk").
  Player: shk startedok
  stop(shk).
  ok
  start("shk").
  {already_started,&lt;0.268.0&gt;}
  </code></pre>
  
  <p>But:</p>
  
  <pre><code>stop(player).
  ok
  </code></pre>
  
  <p>is work.</p>
  
  <p>How can i run gen_server by name and stop by name?</p>
  
  <p>Thank you.</p>