-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
181 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*<$ | ||
For the asynchronous graph programming framework Stratimux and Axium Concept, | ||
generate a quality that will register a subscription to the concepts$ stream. | ||
This allows for the clean closure of concepts that are removed or when the axium itself exits. | ||
$>*/ | ||
/*<#*/ | ||
import { defaultReducer, nullReducer } from '../../../model/concept'; | ||
import { selectPayload } from '../../../model/selector'; | ||
import { createQualitySetWithPayload } from '../../../model/quality'; | ||
import { createMethodWithConcepts } from '../../../model/method'; | ||
import { axiumTimeOut } from '../../../model/time'; | ||
import { Action } from '../../../model/action'; | ||
import { strategySuccess } from '../../../model/actionStrategy'; | ||
|
||
export type AxiumRegisterTimeOutPayload = { | ||
act: Action; | ||
timeOut: number | ||
} | ||
|
||
export const [ | ||
axiumRegisterTimeOut, | ||
axiumRegisterTimeOutType, | ||
axiumRegisterTimeOutQuality | ||
] = createQualitySetWithPayload<AxiumRegisterTimeOutPayload>({ | ||
type: 'register an Action to Axium\'s timerLedger', | ||
reducer: defaultReducer, | ||
methodCreator: (concepts$, semaphore) => createMethodWithConcepts((action, concepts) => { | ||
const { | ||
act, | ||
timeOut | ||
} = selectPayload<AxiumRegisterTimeOutPayload>(action); | ||
axiumTimeOut(concepts, () => act, timeOut); | ||
if (action.strategy) { | ||
return strategySuccess(action.strategy); | ||
} else { | ||
return action; | ||
} | ||
}, concepts$, semaphore) | ||
}); | ||
/*#>*/ |
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
73 changes: 73 additions & 0 deletions
73
src/test/axiumRegisterTimeOut/axiumRegisterTimeOut.test.ts
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*<$ | ||
For the asynchronous graph programming framework Stratimux, generate a tests and demonstrates how register timeout quality functions. | ||
$>*/ | ||
/*<#*/ | ||
import { axiumKick } from '../../concepts/axium/qualities/kick.quality'; | ||
import { axiumRegisterTimeOut } from '../../concepts/axium/qualities/registerTimeOut.quality'; | ||
import { CounterState, counterName, createCounterConcept } from '../../concepts/counter/counter.concept'; | ||
import { counterSelectCount } from '../../concepts/counter/counter.selector'; | ||
import { counterAdd } from '../../concepts/counter/qualities/add.quality'; | ||
import { createAxium } from '../../model/axium'; | ||
import { selectState } from '../../model/selector'; | ||
import { createStage, stageWaitForOpenThenIterate } from '../../model/stagePlanner'; | ||
|
||
test('Axium Register Time Out', (done) => { | ||
const axium = createAxium('timeout defer actions', [createCounterConcept()]); | ||
const plan = axium.plan('timeout add 4 after 10ms', [ | ||
stageWaitForOpenThenIterate(() => axiumKick()), | ||
createStage((_, dispatch) => { | ||
dispatch(axiumRegisterTimeOut({ | ||
act: counterAdd(), | ||
timeOut: 50 | ||
}), { | ||
iterateStage: true, | ||
}); | ||
}), | ||
createStage((concepts, dispatch) => { | ||
const counterState = selectState<CounterState>(concepts, counterName); | ||
expect(counterState?.count).toBe(0); | ||
dispatch(axiumRegisterTimeOut({ | ||
act: counterAdd(), | ||
timeOut: 50 | ||
}), { | ||
iterateStage: true, | ||
}); | ||
}), | ||
createStage((concepts, dispatch) => { | ||
const counterState = selectState<CounterState>(concepts, counterName); | ||
expect(counterState?.count).toBe(0); | ||
dispatch(axiumRegisterTimeOut({ | ||
act: counterAdd(), | ||
timeOut: 50 | ||
}), { | ||
iterateStage: true, | ||
}); | ||
}), | ||
createStage((concepts, dispatch) => { | ||
const counterState = selectState<CounterState>(concepts, counterName); | ||
expect(counterState?.count).toBe(0); | ||
dispatch(axiumRegisterTimeOut({ | ||
act: counterAdd(), | ||
timeOut: 50 | ||
}), { | ||
iterateStage: true, | ||
}); | ||
}), | ||
createStage((concepts, _dispatch, changes) => { | ||
const counterState = selectState<CounterState>(concepts, counterName); | ||
if (changes.length > 0) { | ||
expect(counterState?.count).toBe(4); | ||
setTimeout(() => { | ||
plan.conclude(); | ||
axium.close(); | ||
done(); | ||
}, 10); | ||
} | ||
}, {selectors: [counterSelectCount], beat: 200}), | ||
createStage(() => { | ||
plan.conclude(); | ||
}) | ||
]); | ||
}); | ||
|
||
/*#>*/ |