Git Product home page Git Product logo

Comments (5)

kriskowal avatar kriskowal commented on June 12, 2024

This is new to me. ASAP does play the domains game though, so I would not be surprised whether continuation storage worked or not. Please follow-up if you can. If we don’t have to entrain a dependency, and with good specs, I would not mind supporting it at least to the extent that it is an experiment worth trying.

from asap.

othiym23 avatar othiym23 commented on June 12, 2024

Here is what it would take to make asap CLS-aware (replacing the current definition of the asap function):

function asap(task) {
    if (isNodeJS && process.domain) {
        task = process.domain.bind(task);
    }

    if (isNodeJS && process.namespaces) {
        var namespaces = Object.keys(process.namespaces);
        var length = namespaces.length;
        for (var i = 0; i < length; i++) {
            if (namespaces[i].active) task = namespaces[i].bind(task);
        }
    }

    tail = tail.next = {task: task, next: null};

    if (!flushing) {
        requestFlush();
        flushing = true;
    }
};

@ForbesLindesay It also would be fairly simple to write a shim module that wraps around asap (there are a bunch of CLS shims already) if you don't see the value of making asap support something that isn't part of Node core:

require('continuation-local-storage');
var asap = require('asap');

module.exports = function clsAsap(task) {
    if (process.namespaces) {
        var namespaces = Object.keys(process.namespaces);
        var length = namespaces.length;
        for (var i = 0; i < length; i++) {
            if (namespaces[i].active) task = namespaces[i].bind(task);
        }
    }

    return asap(task);
}

For now, CLS is Node-only, so I'm not really sure how much value you get out of using asap over setImmediate, but this is how you make it play nice with CLS!

from asap.

othiym23 avatar othiym23 commented on June 12, 2024

Oh, and I should point out that I already made a shim for Q which is only really necessary when you're using some other module that messes with continuation chains (like node-redis or node-mysql).

from asap.

kriskowal avatar kriskowal commented on June 12, 2024

With apologies, my inclination is to not do anything special for this kind of extension.

from asap.

ForbesLindesay avatar ForbesLindesay commented on June 12, 2024

Thanks, that seems fair. I may revisit this and consider producing something like asap-cls if I find myself really needing it.

from asap.

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.