Skip to content

Commit 917db92

Browse files
committed
formatting and examples
1 parent 0ebdfb4 commit 917db92

33 files changed

+1365
-1222
lines changed

BaseTask.cfc

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
component {
22

3-
function init() {
4-
fileSystemUtil.createMapping( "/coldbox", getCwd() & "coldbox" );
5-
variables.asyncManager = new coldbox.system.async.AsyncManager();
6-
}
3+
function init(){
4+
fileSystemUtil.createMapping( "/coldbox", getCwd() & "coldbox" );
5+
variables.asyncManager = new coldbox.system.async.AsyncManager();
6+
}
77

8-
function getThreadname() {
8+
function getThreadname(){
99
return createObject( "java", "java.lang.Thread" ).currentThread().getName();
1010
}
1111

12-
public Future function create( required any value, numeric timeout = randRange( 200, 1000 ) ) {
13-
return asyncManager.newFuture( () => {
14-
return compute( value ?: nullValue(), timeout );
15-
} );
16-
}
12+
public Future function create(
13+
required any value,
14+
numeric timeout = randRange( 200, 1000 )
15+
){
16+
return asyncManager.newFuture( () => {
17+
return compute( value ?: nullValue(), timeout );
18+
} );
19+
}
1720

18-
public any function compute( required any value, numeric timeout = 0 ) {
19-
print.greenLine( "Computing from: #getThreadname()#" ).toConsole();
20-
sleep( arguments.timeout );
21-
return arguments.value ?: nullValue();
22-
}
21+
public any function compute(
22+
required any value,
23+
numeric timeout = 0
24+
){
25+
print.greenLine( "Computing from: #getThreadname()#" ).toConsole();
26+
sleep( arguments.timeout );
27+
return arguments.value ?: nullValue();
28+
}
2329

24-
}
30+
}

Run.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
component extends="BaseTask" {
22

3-
function run() {
4-
// scratchpad
5-
systemOutput("Hello World")
6-
}
3+
function run(){
4+
// scratchpad
5+
systemOutput( "Hello World" )
6+
}
77

88
}

build/Watch.cfc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
component {
22

3-
function run() {
4-
// Start the watcher
5-
command( "clear" ).run();
6-
watch()
7-
.paths( "Run.cfc" )
8-
.withDelay( 500 )
9-
.onChange( () => {
10-
command( 'echo Running Task...' ).run()
11-
command( 'task run run' ).run()
12-
} )
13-
.start();
3+
function run(){
4+
// Start the watcher
5+
command( "clear" ).run();
6+
watch()
7+
.paths( "Run.cfc" )
8+
.withDelay( 500 )
9+
.onChange( () => {
10+
command( "echo Running Task..." ).run()
11+
command( "task run run" ).run()
12+
} )
13+
.start();
1414
}
1515

1616
}

exercises/01-intro-to-futures.cfc

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,67 @@
1515
*/
1616
component extends="../BaseTask" {
1717

18-
/**
19-
* Create a future that prints out a greeting immediately.
20-
*/
21-
function partOne() {
22-
return;
23-
}
18+
/**
19+
* Create a future that prints out a greeting immediately.
20+
*/
21+
function partOne(){
22+
return;
23+
}
2424

25-
/**
26-
* Create a future that prints out a greeting after 2 seconds.
27-
*/
28-
function partTwo() {
29-
return;
30-
}
25+
/**
26+
* Create a future that prints out a greeting after 2 seconds.
27+
*/
28+
function partTwo(){
29+
return;
30+
}
3131

32-
/**
33-
* Create a future that _returns_ a message to print out after 5 seconds.
34-
* Print out that message on the main thread.
35-
*/
36-
function partThree() {
37-
return;
38-
}
32+
/**
33+
* Create a future that _returns_ a message to print out after 5 seconds.
34+
* Print out that message on the main thread.
35+
*/
36+
function partThree(){
37+
return;
38+
}
3939

40-
/**
41-
* Create a future that _returns_ a message to print out after 5 seconds.
42-
* Wait for a 3 second timeout before returning a default value.
43-
* Print out that message on the main thread.
44-
*/
45-
function partFour() {
46-
return;
47-
}
40+
/**
41+
* Create a future that _returns_ a message to print out after 5 seconds.
42+
* Wait for a 3 second timeout before returning a default value.
43+
* Print out that message on the main thread.
44+
*/
45+
function partFour(){
46+
return;
47+
}
4848

49-
/**
50-
* Create a future that _returns_ a message to print out after 5 seconds.
51-
* Wait for a 3 second timeout. Do not return a default value.
52-
* See what happens on the main thread
53-
* - when you do not wait for the future to complete?
54-
* - when you wait for the future to complete?
55-
*/
56-
function partFive() {
57-
return;
58-
}
49+
/**
50+
* Create a future that _returns_ a message to print out after 5 seconds.
51+
* Wait for a 3 second timeout. Do not return a default value.
52+
* See what happens on the main thread
53+
* - when you do not wait for the future to complete?
54+
* - when you wait for the future to complete?
55+
*/
56+
function partFive(){
57+
return;
58+
}
5959

60-
function run() {
61-
print.blueLine( "Running all `01-intro-to-futures` exercises" ).toConsole();
62-
print.yellowLine( "Press Ctrl-C to exit" ).line().toConsole();
60+
function run(){
61+
print.blueLine( "Running all `01-intro-to-futures` exercises" ).toConsole();
62+
print
63+
.yellowLine( "Press Ctrl-C to exit" )
64+
.line()
65+
.toConsole();
6366

64-
partOne();
65-
partTwo();
66-
partThree();
67-
partFour();
68-
partFive();
67+
partOne();
68+
partTwo();
69+
partThree();
70+
partFour();
71+
partFive();
6972

70-
while ( true ) {
73+
while ( true ) {
7174
if ( !isNull( checkInterrupted() ) ) {
7275
return;
7376
}
7477
sleep( 100 );
7578
}
76-
}
79+
}
7780

78-
}
81+
}

0 commit comments

Comments
 (0)