-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-creating-future.cfc
30 lines (25 loc) · 1.16 KB
/
05-creating-future.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
26
27
28
29
30
component extends="../BaseTask" {
function run(){
print.blueLine( "Starting from: #getThreadname()#" )
var future = asyncManager
.newFuture( () => compute( 2 ) )
.then( ( data ) => {
// Where is this executing? same thread?
// Think about it, we want a non-blocking mode.
// print.redLine( "Executing from: #getThreadname()#" )
print.greenLine( data ).toConsole();
// return data;
} );
// Get the results and print: Remember, we are blocking here
// print.blueLine( "Future: " & future.get() );
// print.blueLine( "Future: " & future.get( timeout:1000 ) );
// print.blueLine( "Future: " & future.get( timeout:1000, defaultValue: 5 ) );
// print.blueLine( "Future: " & future.getNow( 20 ) );
// 1. Why is the value empty?
// 2. Add a return to the then(), if not, it evaluates to empty.
// 3. Change to thenRun() to avoid these mistakes of returning data
// 4. What happens if the computation is taking too long? and we add a timeout?
// 5. But why a nasty exception, let use a default value now, woot woot!
// 6. There is also a getNow() which is get whatever you have NOW or return a default value! It's like `timeout:0`
}
}