Skip to content

Commit

Permalink
NEW: FTN12 v1.13 #newInstance() support
Browse files Browse the repository at this point in the history
  • Loading branch information
andvgal committed Jan 8, 2020
1 parent 8cd7a03 commit db2fe05
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
10 changes: 10 additions & 0 deletions AsyncSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ class AsyncSteps {

/**
* Execute AsyncSteps with Promise interface
* @alias AsyncSteps#promise
* @returns {Promise} - promise wrapper for AsyncSteps
*/
promise() {
Expand Down Expand Up @@ -593,6 +594,15 @@ class AsyncSteps {
} );
}

/**
* Create a new instance of AsyncSteps for independent execution
* @alias AsyncSteps#newInstance
* @returns {AsyncSteps} new instance
*/
newInstance() {
return new AsyncSteps( null, this._async_tool );
}

/**
* Not standard API for assertion with multiple instances of the module.
* @private
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=== (next)
CHANGED: deps maintenance
NEW: FTN12 v1.13 #newInstance() support

=== 2.4.2 (2019-09-27) ===
CHANGED: deps maintenance
Expand Down
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Additionally, it supports async/Promise integration as step through `as.await()`
Reference implementation of:

FTN12: FutoIn Async API
Version: 1.11
Version: 1.13

Spec: [FTN12: FutoIn Async API v1.x](https://specs.futoin.org/final/preview/ftn12_async_api-1.html)

Expand Down Expand Up @@ -749,6 +749,8 @@ Execute all remaining events in the internal queue
* [.forEach(map_or_list, func, [label])](#AsyncSteps+forEach)[<code>AsyncSteps</code>](#AsyncSteps)
* [.successStep()](#AsyncSteps+successStep)[<code>AsyncSteps</code>](#AsyncSteps)
* [.await(promise, [onerror])](#AsyncSteps+await)[<code>AsyncSteps</code>](#AsyncSteps)
* [.promise()](#AsyncSteps+promise) ⇒ <code>Promise</code>
* [.newInstance()](#AsyncSteps+newInstance)[<code>AsyncSteps</code>](#AsyncSteps)
* [.success([..._arg])](#AsyncSteps+success)
* [.setTimeout(timeout_ms)](#AsyncSteps+setTimeout)[<code>AsyncSteps</code>](#AsyncSteps)
* [.setCancel(oncancel)](#AsyncSteps+setCancel)[<code>AsyncSteps</code>](#AsyncSteps)
Expand Down Expand Up @@ -922,6 +924,20 @@ Integrate a promise as a step.
| promise | <code>Promise</code> | promise to add as a step |
| [onerror] | <code>function</code> | error handler to check |

<a name="AsyncSteps+promise"></a>

### asyncSteps.promise() ⇒ <code>Promise</code>
Execute AsyncSteps with Promise interface

**Kind**: instance method of [<code>AsyncSteps</code>](#AsyncSteps)
**Returns**: <code>Promise</code> - - promise wrapper for AsyncSteps
<a name="AsyncSteps+newInstance"></a>

### asyncSteps.newInstance() ⇒ [<code>AsyncSteps</code>](#AsyncSteps)
Create a new instance of AsyncSteps for independent execution

**Kind**: instance method of [<code>AsyncSteps</code>](#AsyncSteps)
**Returns**: [<code>AsyncSteps</code>](#AsyncSteps) - new instance
<a name="AsyncSteps+success"></a>

### asyncSteps.success([..._arg])
Expand Down Expand Up @@ -1029,6 +1045,8 @@ Continue loop execution from the next iteration, throws exception
* [.forEach(map_or_list, func, [label])](#AsyncSteps+forEach)[<code>AsyncSteps</code>](#AsyncSteps)
* [.successStep()](#AsyncSteps+successStep)[<code>AsyncSteps</code>](#AsyncSteps)
* [.await(promise, [onerror])](#AsyncSteps+await)[<code>AsyncSteps</code>](#AsyncSteps)
* [.promise()](#AsyncSteps+promise) ⇒ <code>Promise</code>
* [.newInstance()](#AsyncSteps+newInstance)[<code>AsyncSteps</code>](#AsyncSteps)
* [.success([..._arg])](#AsyncSteps+success)
* [.setTimeout(timeout_ms)](#AsyncSteps+setTimeout)[<code>AsyncSteps</code>](#AsyncSteps)
* [.setCancel(oncancel)](#AsyncSteps+setCancel)[<code>AsyncSteps</code>](#AsyncSteps)
Expand Down Expand Up @@ -1202,6 +1220,20 @@ Integrate a promise as a step.
| promise | <code>Promise</code> | promise to add as a step |
| [onerror] | <code>function</code> | error handler to check |

<a name="AsyncSteps+promise"></a>

### asyncSteps.promise() ⇒ <code>Promise</code>
Execute AsyncSteps with Promise interface

**Kind**: instance method of [<code>AsyncSteps</code>](#AsyncSteps)
**Returns**: <code>Promise</code> - - promise wrapper for AsyncSteps
<a name="AsyncSteps+newInstance"></a>

### asyncSteps.newInstance() ⇒ [<code>AsyncSteps</code>](#AsyncSteps)
Create a new instance of AsyncSteps for independent execution

**Kind**: instance method of [<code>AsyncSteps</code>](#AsyncSteps)
**Returns**: [<code>AsyncSteps</code>](#AsyncSteps) - new instance
<a name="AsyncSteps+success"></a>

### asyncSteps.success([..._arg])
Expand Down
9 changes: 9 additions & 0 deletions lib/AsyncStepProtector.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ class AsyncStepProtector {
return this;
}


/**
* @private
* @override
*/
newInstance() {
return this._root.newInstance();
}

/**
* @private
* @override
Expand Down
2 changes: 1 addition & 1 deletion misc/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Additionally, it supports async/Promise integration as step through `as.await()`
Reference implementation of:

FTN12: FutoIn Async API
Version: 1.11
Version: 1.13

Spec: [FTN12: FutoIn Async API v1.x](https://specs.futoin.org/final/preview/ftn12_async_api-1.html)

Expand Down
25 changes: 25 additions & 0 deletions test/unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,31 @@ if ( typeof Promise !== 'undefined' ) {
} );
} );
} );

describe( '#newInstance', function() {
it( 'should create on root object', function( done ) {
const as = async_steps();
const as2 = as.newInstance();
expect( as2 ).not.equal( as );
expect( as2 ).instanceof( async_steps.AsyncSteps );
as2.add( ( as ) => done() ).execute();
} );

it( 'should create on ASP object', function( done ) {
const as = async_steps();
as.add( ( as ) => {
try {
const as2 = as.newInstance();
expect( as2 ).not.equal( as._root );
expect( as2 ).instanceof( async_steps.AsyncSteps );
as2.add( ( as ) => done() ).execute();
} catch ( e ) {
done( e );
}
} );
as.execute();
} );
} );
}

describe( '.assertAS', function( done ) {
Expand Down

0 comments on commit db2fe05

Please sign in to comment.