PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

abapify/promise

A Promise and async/await implementation for ABAP, modelled on JavaScript's Promise API, that runs a resolver as a background task and offers all, race, resolve, reject and all_settled.

Creating a zcl_promise with a resolver runs that resolver as a serialised asynchronous task in the background, so the rest of the calling program keeps running instead of waiting on it immediately; a handler's on_fulfilled or on_rejected method, or an await call inside a class that inherits from zcl_abap_async, picks up the result once the task resolves or rejects. Promise=>all combines several promises into one that resolves with all their results, or rejects with the reason of whichever one rejects first, and the same class exposes race, resolve, reject and all_settled. The maintainer notes the benefit is small for a single promise and grows for a promise=>all call across several.

Facts

Last pushLicenceMIT

Where it sits

Lives in
Provides
Parallel processingABAPParallel processingcapabilitySplitting one run's work across several work processes so that it finishes sooner, and collecting what each part returned before the run goes on. [Async processing](capability:async-processing) is the neighbouring concern: work deferred past the request with a guarantee that it eventually happens, where parallel processing is throughput inside a run that waits for its results.

Who is behind it

abapifyabapifyOrganisationMaintains this
In the atlas: maintains 9
@abapify
maintainerPetr PlenkovPersonContributes to this
In the atlas: contributes to 13
@ThePlenkov
1 contributor

Before choosing this

Signals

ActivityQuietNo published releases; repository quiet for 36 months

It publishes no releases, and its repository has been quiet for at least 24 full months. This may be normal for stable software; check whether its current state still fits your use.

What it declares

Every artifact

Type
Package
Origin
Independently maintained

As a package

Where it runs
does not say
Distributed through
does not say

Connections1

README

quoted from abapify/promise under MIT, read
abapify/promise/README.mdOn GitHub

Let's make ABAP async!

To understand how this class work use this as a reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

How to use

Promise

what runs in js

new Promise( ( resolve, reject ) => { resolve( 'OK' ) } ).then( ( value ) => console.log( value )  ) // OK

now runs in ABAP ( with a bit more lines of course )

REPORT ZTEST_PROMISE_OK.

" Promise Resolver
" Must implement then method with mandatory resolve or reject method calls from inside
CLASS lcl_ok DEFINITION INHERITING FROM zcl_promise_resolver.
  PUBLIC SECTION.
    METHODS then REDEFINITION.
ENDCLASS.

CLASS lcl_ok IMPLEMENTATION.
  METHOD then.
    " resolve is declared in zcl_promise_resolver
    resolve( |OK| ).
  ENDMETHOD.
ENDCLASS.

" Promise handler
" has on_fulfilled and on_rejected callbacks with default empty implementation
CLASS lcl_ok_handler DEFINITION INHERITING FROM zcl_promise_handler.
  PUBLIC SECTION.
    METHODS ON_FULFILLED REDEFINITION.
ENDCLASS.

CLASS lcl_ok_handler IMPLEMENTATION.
  METHOD on_fulfilled.
    " ideally resolver needs to know which type it expects to have as a result
    write cast string( with )->*.
  ENDMETHOD.
endclass.

START-OF-SELECTION.
    
  new zcl_promise( new lcl_ok( ) )->then( new lcl_ok_handler( ) ).
So what's the purpose?

You probably think, why we wouldn't just run write 'OK'

The answer is in the following sequence diagram

zcl_promise

What promise class does during inititalization - is creating an asyncronous task with serialized resolver instance. Asyncronous task deserialises resolver and executes it. It may be time consuming operation, for example some calculation, query, or http request. So why won't let the rest of abap code work for something else? So when your code decides that it's time to get data from promise and only then actually triggers for wait statement. Once an asynctronous task is done by triggering resolve/reject method in your resolver instance - it will serialize again the response and send back to your main session.

You may not see the desired effect for single operations - but for promise=>all call the effect can be huge!

And what about async/await?

To use full power of promises we can also use await functions.

So mentioned above example may look a bit differently:

async function() {
console.log( await new Promise( ( resolve, reject ) => { resolve( 'OK' ) } ) ) // OK
}

now works in ABAP

REPORT ZTEST_PROMISE_OK_AWAIT.

" Promise Resolver
" Must implement then method with mandatory resolve or reject method calls from inside
CLASS lcl_ok DEFINITION INHERITING FROM zcl_promise_resolver.
  PUBLIC SECTION.
    METHODS then REDEFINITION.
ENDCLASS.

CLASS lcl_ok IMPLEMENTATION.
  METHOD then.
    " resolve is declared in zcl_promise_resolver
    resolve( |OK| ).
  ENDMETHOD.
ENDCLASS.

CLASS lcl_app DEFINITION INHERITING FROM zcl_abap_async.
  PUBLIC SECTION.
    METHODs start.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD start.
    " we expect result as ref to string
    write cast string(
      " in case if it's async class ( child of async )
      " you can just use await of any promise
      await( new zcl_promise( new lcl_ok( ) ) ) )->*.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  " start the app
  new lcl_app( )->start( ).

Other methods

Promise=>all

Returns a new promise, resolved with array of promises results or rejected with a reason of the first rejected promise

Promise=>race
Promise=>resolve

Returns resolved promise

Promise=>reject

Returns rejected promise

Promise=>all_settled
MIT, read
Parallel processing
  1. ABAPParallelizationServiceFramework for running ABAP work units in parallel tasksfrom ABAP
  2. COROUTINES4ABAPCoroutine framework for ABAP with awaitable resultsfrom ABAP
  3. zconcurrency_apiParallel task library for ABAP over the SPTA frameworkfrom ABAP
  4. RFC_TOOLSA wrapper class for calling asynchronous RFC function modules in parallel from ABAP, one instance per parallel task.from ABAP
  5. zthreadThreading library for ABAP modelled on Java's Thread and Runnablefrom ABAP

Details

Sources3
dotabapdiscovered herechecked
github.com/abapify/promisetree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
discovered viadotabap
first seen in the atlas
ecosystem and domainabap, operations-and-runtime
abaplint
issues under its own abaplint configuration588
lines1,710
statements1,024
objects16
files43
analysed, main
abaplint version2.120.84
Contributors1

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent
Ref
artifact:abapify-promise
JSON
/artifacts/abapify-promise.json
MCP
Connecting an agent