Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise flattening #12

Open
hdgarrood opened this issue May 16, 2020 · 0 comments
Open

Promise flattening #12

hdgarrood opened this issue May 16, 2020 · 0 comments

Comments

@hdgarrood
Copy link

Because promises of promises are automatically "flattened", any nesting of promises is likely to lead to runtime errors. Consider:

module Main where

import Prelude
import Effect (Effect)
import Effect.Console (logShow)
import Effect.Promise (Promise)
import Effect.Promise as Promise
import Effect.Promise.Console as Promise.Console

main = Promise.runPromise logShow logShow do
  hello <- Promise.resolve (Promise.resolve "hello")
  hello' <- hello
  Promise.Console.log (hello' <> ", world")

which, when run, outputs this:

TypeError: promise.then is not a function
    at Object.exports.thenImpl (/home/harry/code/ps-scratch/output/Effect.Promise/foreign.js:2:18)
    at /home/harry/code/ps-scratch/output/Effect.Promise/index.js:55:29
    at /home/harry/code/ps-scratch/output/Data.Function/index.js:16:24
    at /home/harry/code/ps-scratch/output/Main/index.js:11:70

I'm not sure if this is fixable but it may be worth documenting, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant