Code Monkey home page Code Monkey logo

Comments (6)

wmertens avatar wmertens commented on June 2, 2024

Could you elaborate? It's not clear to me what you are trying to achieve and how Q is involved in it

from q.

indown avatar indown commented on June 2, 2024

Could you elaborate? It's not clear to me what you are trying to achieve and how Q is involved in it

design/README.md

That's my problem with this document design/README.md.

from q.

wmertens avatar wmertens commented on June 2, 2024

If you don't call ref on the callback value, the callback might not return a promise and then you wouldn't be able to call p.then(...).then(...)

from q.

indown avatar indown commented on June 2, 2024

If you don't call ref on the callback value, the callback might not return a promise and then you wouldn't be able to call p.then(...).then(...)

I try only to use "callback(value)". it would be able to call p.then(...).then(...)
https://jsbin.com/cozuluxido/3/edit?html,js,console,output
Can you provide an example where it doesn't work๏ผŸ

from q.

kriskowal avatar kriskowal commented on June 2, 2024

p.then(() => 1) would return 1, would it not?

Of course, there is a school of thought that promises should be strict monads, in which case, the author of the callback would be obliged to wrap/lift the return value in order to satisfy the type of then (which would decompose into map and flatMap).

So p.then(() => ref(1)) would return a promise.

from q.

indown avatar indown commented on June 2, 2024

p.then(() => 1) would return 1, would it not?

Of course, there is a school of thought that promises should be strict monads, in which case, the author of the callback would be obliged to wrap/lift the return value in order to satisfy the type of then (which would decompose into map and flatMap).

So p.then(() => ref(1)) would return a promise.

promise: {
            then: function (_callback) {
                let result = defer();
                let callback = function (value) {
                    result.resolve(_callback(value));
                };
                if (pending) {
                    pending.push(callback);
                } else {
                    value.then(callback);
                }
                return result.promise;
            }
        }

So p.then(() => 1) would return a promise.
There is an example on https://jsbin.com/cozuluxido/3/edit?html,js,console,output

from q.

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.