Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.prolog > #14572

The magical "async" keyword again [Node.js v20.0.0] (Was: timers and tasks testing framework [Node.js v20.0.0])

From Mild Shock <janburse@fastmail.fm>
Newsgroups comp.lang.prolog
Subject The magical "async" keyword again [Node.js v20.0.0] (Was: timers and tasks testing framework [Node.js v20.0.0])
Date 2025-06-23 13:10 +0200
Message-ID <103bcmh$15ubr$1@solani.org> (permalink)
References <1034bs9$1364p$1@solani.org> <1034c6f$136cd$1@solani.org> <1034dhp$1374f$1@solani.org> <103bcdl$15u3h$1@solani.org>

Show all headers | View raw


Again JavaScript shines since the keyword "async"
makes the difference. We have recently experienced
its benefit, since we could remove all new Promise()
calls in our code where we are juggling with tasks.

new Promise() is only needed for callbacks that
then call resolve() or reject(), but task can
just use await and try catch. Now without
the keyword its a traditional test case:

test('synchronous failing test', (t) => {
   // This test fails because it throws an exception.
   assert.strictEqual(1, 2);
});

With the keyword its a test case that
can test timers and tasks:

test('asynchronous passing test', async (t) => {
   // This test passes because the Promise returned by the async
   // function is settled and not rejected.
   assert.strictEqual(1, 1);
});

Mild Shock schrieb:
> A flesh an bood cooperative multitasking Prolog system
> is sometimes tricky to do. We were agonizing over the
> last days how we could test our timers and tasks.
> 
> Our existing framework doesn't work, since it neither
> waits for a timer callback to be fired and to complete,
> nor for a task to complete. But its seems its just an
> instance of a Promise again.
> 
> Turn the test case itself into a Promise, and wait for
> it. In Prolo terms, the test case is a success when the
> .then() port gets reached with SUCCESS, or its a failure
> if the .then() port gets reached with FAILURE or if the
> 
> the .catch() port gets reached. Interesting framework
> that does just that:, whereby the use assert, to turn
> FAILURE into an exception:
> 
> Node.js v20.0.0 - The test runner is now stable.
> https://nodejs.org/api/test.html#describe-and-it-aliases
> 
> BTW: Quite inventive vocabulary...
> 
> 
> 

Back to comp.lang.prolog | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Prolog missed the Web 2.0 Bandwagon Mild Shock <janburse@fastmail.fm> - 2025-06-20 21:13 +0200
  IntelliJ just created Mellum, its open source (Was: Prolog missed the Web 2.0 Bandwagon) Mild Shock <janburse@fastmail.fm> - 2025-06-20 21:18 +0200
    Re: IntelliJ just created Mellum, its open source (Was: Prolog missed the Web 2.0 Bandwagon) Mild Shock <janburse@fastmail.fm> - 2025-06-20 21:41 +0200
      timers and tasks testing framework Node.js v20.0.0] (Was: IntelliJ just created Mellum, its open source) Mild Shock <janburse@fastmail.fm> - 2025-06-23 13:05 +0200
        The magical "async" keyword again [Node.js v20.0.0] (Was: timers and tasks testing framework [Node.js v20.0.0]) Mild Shock <janburse@fastmail.fm> - 2025-06-23 13:10 +0200
          OpenAPI Specification (OAS) goes full Monty [AsyncAPI] (Was: The magical "async" keyword again [Node.js v20.0.0]) Mild Shock <janburse@fastmail.fm> - 2025-06-24 08:16 +0200
          OpenAPI Specification (OAS) goes full Monty [AsyncAPI] (Was: The magical "async" keyword again [Node.js v20.0.0]) Mild Shock <janburse@fastmail.fm> - 2025-06-24 08:17 +0200
  constant caching test case / Prolog orthodoxification (Was: Prolog missed the Web 2.0 Bandwagon) Mild Shock <janburse@fastmail.fm> - 2025-06-24 01:06 +0200
    Teachers have better quality than Nerds (Was: constant caching test case / Prolog orthodoxification) Mild Shock <janburse@fastmail.fm> - 2025-06-24 01:12 +0200
      ISO is loosing it because it gives in to Teachers (Was: Teachers have better quality than Nerds) Mild Shock <janburse@fastmail.fm> - 2025-06-24 01:26 +0200
        Where APIs Meet AI: Building Tomorrow's Intelligent Ecosystems (Was: ISO is loosing it because it gives in to Teachers) Mild Shock <janburse@fastmail.fm> - 2025-06-24 08:24 +0200
  A library(pio) for the Web 2.0 (Was: Prolog missed the Web 2.0 Bandwagon) Mild Shock <janburse@fastmail.fm> - 2025-06-25 15:17 +0200
    Corr. (Was: A library(pio) for the Web 2.0) Mild Shock <janburse@fastmail.fm> - 2025-06-25 15:19 +0200

csiph-web