Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit 72782c1

Browse files
committed
fix(FlowProviderMixin): stop all flows when stoping
1 parent 27925e2 commit 72782c1

4 files changed

Lines changed: 60 additions & 15 deletions

File tree

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ possible to bundle steps in a flow. From the outside the flows acts as a single
3939
### Table of Contents
4040

4141
- [Flow](#flow)
42-
- [createEndpoints](#createendpoints)
43-
- [endpointFor](#endpointfor)
44-
- [connectEndpoints](#connectendpoints)
45-
- [connectRootEndpoints](#connectrootendpoints)
42+
- [createEndpoints](#createendpoints)
43+
- [endpointFor](#endpointfor)
44+
- [connectEndpoints](#connectendpoints)
45+
- [connectRootEndpoints](#connectrootendpoints)
46+
- [name](#name)
4647
- [willBeUnregistered](#willbeunregistered)
4748

4849
## Flow
@@ -51,13 +52,16 @@ possible to bundle steps in a flow. From the outside the flows acts as a single
5152

5253
This is the flow implementation.
5354
It holds all the steps.
55+
Declares the following properties:
56+
\-steps
57+
\-autostart
5458

5559
**Parameters**
5660

57-
- `config`
58-
- `owner`
61+
- `config` {Object} The definition used to create the flow
62+
- `owner` {Object} owner of the flow
5963

60-
## createEndpoints
64+
### createEndpoints
6165

6266
The flow has no real endpoints. It only has proxies.
6367
So just return the configuration
@@ -66,7 +70,7 @@ So just return the configuration
6670

6771
- `stepDefinition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The step configuration
6872

69-
## endpointFor
73+
### endpointFor
7074

7175
Find endpoint for given expression
7276

@@ -78,20 +82,24 @@ Find endpoint for given expression
7882

7983
Returns **Endpoint** found endpoint
8084

81-
## connectEndpoints
85+
### connectEndpoints
8286

8387
set the target endpoints
8488

8589
**Parameters**
8690

8791
- `stepDefinition`
8892

89-
## connectRootEndpoints
93+
### connectRootEndpoints
9094

9195
A flow has only endpoint proxies. These will be replaced by the original endpoints
9296
of the sub steps
9397
get the original endpoints for the Flow.
9498

99+
### name
100+
101+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'kronos-flow'
102+
95103
## willBeUnregistered
96104

97105
Deletes a flow from the stored flow definitions. If the flow

src/flow-provider-mixin.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function FlowProviderMixin(superclass) {
1313
withEvents: true,
1414
hasBeenRegistered: async flow => {
1515
if (flow.autostart) {
16-
flow.start();
16+
return flow.start();
1717
}
1818
},
1919

@@ -30,5 +30,17 @@ export function FlowProviderMixin(superclass) {
3030
}
3131
});
3232
}
33+
34+
/**
35+
* Stops execution and frees all used flows.
36+
* It will stop each flow.
37+
* @return {Promise} that fullfills when the manager has stopped
38+
*/
39+
async _stop() {
40+
await Promise.all(
41+
Object.keys(this.flows).map(name => this.flows[name].stop())
42+
);
43+
return super._stop();
44+
}
3345
};
3446
}

src/flow.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ export { FlowProviderMixin };
1010
* Declares the following properties:
1111
* -steps
1212
* -autostart
13-
* @param manager {object} The kronos-service-manager
14-
* @param name {string} The name of this step
15-
* @param stepDefinition {object} The definition used to create the step
13+
* @param config {Object} The definition used to create the flow
14+
* @param owner {Object} owner of the flow
1615
*/
1716
export class Flow extends Step {
18-
1917
/**
2018
* @return {string} 'kronos-flow'
2119
*/

tests/flow-provider-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Service } from 'kronos-service';
2+
import { FlowProviderMixin } from '../src/flow-provider-mixin';
3+
import { Flow } from '../src/flow';
4+
import test from 'ava';
5+
6+
class FlowProvider extends FlowProviderMixin(Service) {
7+
static get name() {
8+
return 'flow-provider';
9+
}
10+
11+
get owner() {
12+
return this;
13+
}
14+
15+
// TODO
16+
emit() {}
17+
}
18+
19+
test('flow provider', async t => {
20+
const fp = new FlowProvider();
21+
22+
await fp.start();
23+
24+
t.is(fp.state, 'running');
25+
26+
fp.registerFlow(Flow);
27+
});

0 commit comments

Comments
 (0)