-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from Atry/await-promise
Let Await accept js.Promise
- Loading branch information
Showing
4 changed files
with
96 additions
and
61 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
keywords-Await/.js/src/main/scala/com/thoughtworks/dsl/keywords/AwaitJS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.thoughtworks.dsl | ||
package keywords | ||
import com.thoughtworks.dsl.domains.Continuation.!! | ||
import scalajs.js | ||
import scala.util.Success | ||
import scala.util.Failure | ||
import scala.util.control.NonFatal | ||
|
||
private trait AwaitJS { this: Await.type => | ||
given [PromiseResult] | ||
: Dsl.IsKeyword[Await[js.Promise[PromiseResult]], PromiseResult] with {} | ||
|
||
given [Value, That]: Dsl[Await[js.Promise[Value]], js.Promise[That], Value] = | ||
Await.apply.liftCo[[X] =>> Dsl[X, js.Promise[That], Value]](_ `then` _) | ||
|
||
extension [FA, A](inline fa: FA)(using | ||
inline notKeyword: util.NotGiven[ | ||
FA <:< Dsl.Keyword | ||
], | ||
inline asFA: FA <:< js.Promise[A] | ||
) | ||
transparent inline def unary_! : A = | ||
Dsl.shift(Await(asFA(fa))): A | ||
} |
5 changes: 5 additions & 0 deletions
5
keywords-Await/.jvm/src/main/scala/com/thoughtworks/dsl/keywords/AwaitJS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.thoughtworks.dsl.keywords | ||
|
||
private trait AwaitJS { this: Await.type => | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters