Giter Club home page Giter Club logo

Comments (3)

ivenmarquardt avatar ivenmarquardt commented on May 18, 2024

OK, I am not sure yet, but I think I've found an impure approach that achieves the sharing:

const Task = structGetter("Task")
  (Task => k => Task(thisify(o => {
    o.runTask = (res, rej) => k(x => {
      o.runTask = l => l(x); // A
      return res(x);
    }, rej);
    
    return o;
  })));

Line A is a destructive update. It isn't harmful though, because it simply replaces the asynchrnous computation with its result wrapped in a continuation. This shouldn't change the behavior of the program, as long as referential transparency holds.

Additionally, error cases are not shared as desired.

However, I need to test this in larger projects first.

from scriptum.

ivenmarquardt avatar ivenmarquardt commented on May 18, 2024

The last sharing approach also defers the impure effect (the destructive update of the Task object) to the execution of the Task computation when everything is impure anyways. That means everything remains pure until you run runTask. Pure sharing so to speak.

from scriptum.

ivenmarquardt avatar ivenmarquardt commented on May 18, 2024

I've just tested it in a larger code base and it works as expected. This was a major issue and I am quite relieved that I could solve it. This issue can probably be closed in the next few days.

from scriptum.

Related Issues (20)

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.