Giter VIP home page Giter VIP logo

Comments (9)

fishcakez avatar fishcakez commented on August 24, 2024

Here's an example how it could be done, very easy :/.
https://github.com/fishcakez/agent_telnet/blob/code_change/rel/agent_telnet.appup
https://github.com/fishcakez/agent_telnet/blob/code_change/lib/agent_telnet/supervisor.ex#L9-10
https://github.com/fishcakez/agent_telnet/blob/code_change/lib/agent_telnet/protocol.ex#L34-L36
fishcakez@407255f

from xgen.

josevalim avatar josevalim commented on August 24, 2024

very easy :/

Do you mean "very easy :)" or "not very easy :/" ? :P

from xgen.

fishcakez avatar fishcakez commented on August 24, 2024

I mean very easy, :/ because API is not very nice.

On 11 April 2014 19:51, José Valim [email protected] wrote:

very easy :/

Do you mean "very easy :)" or "not very easy :/" ? :P

Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-40240610
.

from xgen.

josevalim avatar josevalim commented on August 24, 2024

Ah, got it. I still think we should allow a { M, F, A } to be given as state in code change and simply apply that to the state. And starting considering allowing { M, F, A } everywhere else too.

from xgen.

fishcakez avatar fishcakez commented on August 24, 2024

do you mean?

code_change(_vsn, state, { m, f, a }), do: { :ok, Kernel.apply(m, f, [state | a]) }
{update, module, { advanced, { m, f, [a] } }}

That works very nicely!

from xgen.

josevalim avatar josevalim commented on August 24, 2024

Yes, exactly!

from xgen.

josevalim avatar josevalim commented on August 24, 2024

We just need to work on it and write a test.

from xgen.

fishcakez avatar fishcakez commented on August 24, 2024

This ones free 👍

  test ":sys.change_code/4 with mfa" do
    { :ok, pid } = Agent.start_link(fn -> %{} end)
    :ok = :sys.suspend(pid)
    mfa = { Map, :put, [:hello, :world] }
    assert :sys.change_code(pid, __MODULE__, "vsn", mfa) == :ok
    :ok = :sys.resume(pid)
    assert Agent.get(pid, &Map.get(&1, :hello)) == :world
    assert Agent.stop(pid) == :ok
  end

  test ":sys.change_code/4 with raising mfa" do
    { :ok, pid } = Agent.start_link(fn -> %{} end)
    :ok = :sys.suspend(pid)
    mfa = { :erlang, :error, [] }
    assert match?({ :error, _ }, :sys.change_code(pid, __MODULE__, "vsn", mfa))
    :ok = :sys.resume(pid)
    assert Agent.get(pid, &(&1)) == %{}
    assert Agent.stop(pid) == :ok
  end

from xgen.

josevalim avatar josevalim commented on August 24, 2024

The test cases worked like a charm! Thank you! ❤️ 💚 💙 💛 💜

from xgen.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.