Skip to content

Instantly share code, notes, and snippets.

@dbrattli
Created October 14, 2018 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrattli/43a3e2e70547fec09067ae3d70689ee7 to your computer and use it in GitHub Desktop.
Save dbrattli/43a3e2e70547fec09067ae3d70689ee7 to your computer and use it in GitHub Desktop.
Promise Then Extension
// Make a new extension method on Promise
type Promise<'a> with
member this.Then(fn: 'a -> Promise<'b>) : Promise<'b> =
let newPromise = Promise<'b> ()
this.Then(fun a ->
let tmpPromise = fn a
tmpPromise.Then(newPromise.Resolve).Catch(newPromise.Reject)
|> ignore
).Catch(newPromise.Reject)
|> ignore
newPromise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment