CoreCombinators.dcl 4.47 KB
Newer Older
1
definition module CoreCombinators
2 3 4 5
/**
* This is the kernel module for the specification of workflows. It contains the core set of iTasks combinators
* with which additional combinators can be defined.
*/
6
from Time				import :: Timestamp
Bas Lijnse's avatar
Bas Lijnse committed
7
from LayoutCombinators	import :: SetLayout, :: AfterLayout, :: ModifyLayout, :: Layout
8
import Task, Shared
9

10
import iTaskClass
11
derive class iTask ParallelTaskType, WorkOnStatus
12
/**
Bas Lijnse's avatar
Bas Lijnse committed
13
* Adds a result transformation function to a task.
14 15
* The resulting task is still considered a single step in the workflow.
*
16
* @param Function: The transformation function. It works on maybe's to also map over instable tasks.
17
* @param Task: The task to which the transformation function is added
18
*
Bas Lijnse's avatar
Bas Lijnse committed
19
* @return The transformed task
20
*/
Bas Lijnse's avatar
Bas Lijnse committed
21
transform :: ((TaskValue a) -> TaskValue b) !(Task a) -> Task b | iTask a & iTask b 
22

Bas Lijnse's avatar
Bas Lijnse committed
23 24 25 26 27 28 29 30 31 32
/**
* Projects the result of a task in a share when its result changes.
* The resulting task is still considered a single step in the workflow.
*
* @param The projection function
* @param The share onto which the result should be projected
* @param The task that provides the result

* @return The modified task
*/
Steffen Michels's avatar
Steffen Michels committed
33
project	:: ((TaskValue a) r -> Maybe w) (ReadWriteShared r w) !(Task a) -> Task a | iTask a
Bas Lijnse's avatar
Bas Lijnse committed
34

35 36 37 38 39 40 41
/**
* The generic sequential combinator.
* It does a task followed by one out of a given list of continuations.
* Once the transition to the continuation has been made it cannot be reversed.
*
* @param Task: The first step in the sequence
* @param Continuations: A set of continuation definitions from which one is selected
Bas Lijnse's avatar
Bas Lijnse committed
42 43 44 45
*   -OnValue: inspect the value, step if the predicate matches
*	-OnAction: enable an action if the predicate matches, step if the actions is chosen
*	-OnException: Provides an exception handler for exceptions of type e
*	-OnAllExceptions: Provides an exception handler that catches all exceptions
46 47
*
*	@return The combined task
48
*/
Steffen Michels's avatar
Steffen Michels committed
49
step :: !(Task a) [TaskStep a b] -> Task b | iTask a & iTask b
50 51

:: TaskStep a b
Bas Lijnse's avatar
Bas Lijnse committed
52 53 54 55
	= 		OnValue 			((TaskValue a)	-> Maybe (Task b))
	|		OnAction	Action	((TaskValue a)	-> Maybe (Task b))
	| E.e:	OnException			(e				-> Task b)			 & iTask e
	| 		OnAllExceptions		(String			-> Task b)
56
/**
57
* All-in-one swiss-army-knife parallel task creation
58
*
59 60
* @param Description: The (overloaded) task description
* @param Tasks: The list of tasks to run in parallel, each task is given a view on the status of all tasks in the set
61
* @return The sum of all results
62 63
* 
* @gin False
64
*/
Bas Lijnse's avatar
Bas Lijnse committed
65
parallel :: !d ![(!ParallelTaskType,!ParallelTask a)] -> Task [(!TaskTime,!TaskValue a)] | descr d & iTask a
66
					
67
/**
68 69
* Get the shared state of a task list
*/
Bas Lijnse's avatar
Bas Lijnse committed
70
taskListState :: !(SharedTaskList a) -> ReadOnlyShared [TaskValue a]
71 72 73
/**
* Get the properties share of a task list
*/
74
taskListMeta	:: !(SharedTaskList a) -> ReadOnlyShared [TaskListItem a]
75

76
//Task list manipulation 
77 78

/**
79
* Appends a task to a task list
80
*/
81
appendTask :: !ParallelTaskType !(ParallelTask a)	!(SharedTaskList a) -> Task TaskId | iTask a
82 83
/**
* Removes (and stops) a task from a task list
84
*/
85
removeTask :: !TaskId								!(SharedTaskList a)	-> Task Void | iTask a
86 87

/**
88 89 90
* State of another process the user works on.
*/
:: WorkOnStatus
91 92
	= WOActive		//* the process is active, the current user works on it
	| WOInUse User	//* the process is active, another user is working on it
93 94 95 96 97 98
	| WOFinished	//* the process is finished
	| WOExcepted	//* an uncaught exception was thrown inside of the process
	| WODeleted		//* the process has been deleted

/**
* Work on a detached task.
99
*
100 101 102 103
* @param Task identification of the task to work on
* 
* @return The state of the task to work on
* @throws WorkOnException
104
*/
105
workOn :: !TaskId -> Task WorkOnStatus
106

107 108
/**
* Execute a task with the identity of the given user
109 110 111 112 113
*
* @param The user with which identity the task is to be executed
* @param The task to do
*
* @return The modified task
114
*/
115
workAs :: !User !(Task a)						-> Task a | iTask a
116

117 118 119 120 121 122 123 124
/**
* Provide a local read/write shared for a task to work on.
*
* @param The initial value of the shared variable
* @param The task which uses the shared variable
*/
withShared :: !b !((Shared b) -> Task a) -> Task a | iTask a & iTask b

125 126 127 128 129
/**
* Fine tune a task by specifying custom layouts, tweaking generic layouts,
* or add additional titles, hints and descriptions
*/
class tune b :: !b !(Task a) -> Task a
130
instance tune	SetLayout				//Set layout algorithm
Bas Lijnse's avatar
Bas Lijnse committed
131
instance tune	AfterLayout				//Apply a modification after a layout has been run
132
instance tune	ModifyLayout			//Modify the existing layout
133 134 135 136 137

/**
*  Fine tune evaluation behaviour
*/
instance tune	LazyRefresh