Browse files

Close file on completion.

Update documentation.
  • Loading branch information...
1 parent 2f531a2 commit 1b57e536f586917c9a8e206ff831388642fd8f7a @markmandel committed May 30, 2012
Showing with 29 additions and 3 deletions.
  1. +18 −0 README.md
  2. +11 −3 sesame/io.cfm
View
18 README.md
@@ -58,6 +58,13 @@ Take an array/struct and group the data into a grouped struct. The closure shoul
* data - the array / struct
* grouping - the closure to return the group key.
+### _queryEach(query data, [function func]) : any ###
+
+Iterates over a query and executes the closure on each row.
+
+* data - the query
+* func - the closure
+
### _unique(any data, [function comparator]) : any ###
Returns an array with all the duplicates removed (i.e. unique). For structs, this iterates through all the values, and returns an array from that, with duplicates removed.
@@ -104,6 +111,17 @@ Iterates from this number up to the given number, inclusive, incrementing by one
* numberTo - the number to go to
* closure - the closure to call with the current count.
+## IO ##
+
+Functions for working with input/output
+
+### _fileLineEach(any file, function handler) : void ###
+
+Read a file and call the closure on each line. Works on either a file ob or path
+
+* file - the file to load
+* handler - closure to take the input
+
## Concurrency ##
View
14 sesame/io.cfm
@@ -27,9 +27,17 @@
public void function _fileLineEach(required any file, required function handler)
{
if(isSimpleValue(arguments.file)) arguments.file = fileOpen(arguments.file);
- while(!fileIsEOF(arguments.file)) {
- var line = fileReadLine(arguments.file);
- handler(line);
+
+ try
+ {
+ while(!fileIsEOF(arguments.file)) {
+ var line = fileReadLine(arguments.file);
+ handler(line);
+ }
+ }
+ finally
+ {
+ fileClose(arguments.file);
}
};

0 comments on commit 1b57e53

Please sign in to comment.