-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseTask.cfc
25 lines (20 loc) · 851 Bytes
/
BaseTask.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
component {
function init() {
fileSystemUtil.createMapping( "/coldbox", getCwd() & "coldbox" );
fileSystemUtil.createMapping( "/testbox", getCwd() & "testbox" );
variables.asyncManager = new coldbox.system.async.AsyncManager();
}
function getThreadname() {
return createObject( "java", "java.lang.Thread" ).currentThread().getName();
}
public Future function create( required any value, numeric timeout = randRange( 200, 1000 ) ) {
return asyncManager.newFuture( () => {
return compute( value ?: nullValue(), timeout );
} );
}
public any function compute( required any value, numeric timeout = 0 ) {
print.greenLine( "Computing from: #getThreadname()#" ).toConsole();
sleep( arguments.timeout );
return arguments.value ?: nullValue();
}
}