-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pierre Haller
committed
Feb 26, 2020
1 parent
50eaa3b
commit b300076
Showing
7 changed files
with
37 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,32 @@ | ||
import executeInSeries from '../utils/executeInSeries'; | ||
import configurable from '../utils/configurable'; | ||
import wait from '../utils/wait'; | ||
|
||
/** | ||
* Execute all Gremlins species at once ; repeat 10ms after for 100 times | ||
* | ||
* const allTogetherStrategy = gremlins.strategies.allTogether(); | ||
* horde.strategy(allTogetherStrategy); | ||
* | ||
* The actual attack duration depends on the number of species in the horde. | ||
*/ | ||
export default () => { | ||
const config = { | ||
export default userConfig => () => { | ||
const defaultConfig = { | ||
delay: 10, // delay in milliseconds between each wave | ||
nb: 100, // number of waves to execute (can be overridden in params) | ||
}; | ||
|
||
const config = { ...defaultConfig, ...userConfig }; | ||
|
||
let stopped; | ||
|
||
const allTogetherStrategy = async (gremlins, params) => { | ||
const nb = params && params.nb ? params.nb : config.nb; | ||
const delay = params && params.delay ? params.delay : config.delay; | ||
const horde = this; | ||
const allTogetherStrategy = async gremlins => { | ||
const { nb, delay } = config; | ||
|
||
stopped = false; | ||
for (let i = 0; i < nb; i++) { | ||
await wait(delay); | ||
if (stopped) { | ||
return Promise.resolve(); | ||
} | ||
await executeInSeries(gremlins, [], horde); | ||
await executeInSeries(gremlins, []); | ||
} | ||
return Promise.resolve(); | ||
}; | ||
allTogetherStrategy.stop = () => { | ||
stopped = true; | ||
}; | ||
|
||
configurable(allTogetherStrategy, config); | ||
|
||
return allTogetherStrategy; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters