Prolog.forEach()
,
execution of
await/2
completes when the Promise resolves and Result is
unified with the value passed to the Promise.then()
method. As an exception to the normal conversion rules, if the result is
a single
String
, it is returned as a Prolog string rather than an
atom. When the Promise is rejected await/2
throws an exception. Note that await/2
allows, for example, downloading a URL from Prolog:
?- FP := fetch("test.pl"), await(FP, Response), TP := Response.text(), await(TP, T). FP = <js_Promise>(4), Response = <js_Response>(5), TP = <js_Promise>(6), T = "% :- debug(js) ...".
Calls to await/2
may be asynchronously aborted by calling
Prolog.abort()
if Promise implements .abort()
.
See section 13.3.2
for implementing such a promise.