Skip to content

Promise flattening #12

@hdgarrood

Description

@hdgarrood

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions