Skip to content
Browse files

Made async methods actually async using setTimeout

  • Loading branch information...
1 parent e09451f commit c4febc2d75545793b26d6f94d7b47f7d0b0dd234 @meltingice meltingice committed
Showing with 31 additions and 26 deletions.
  1. +29 −25 lib/cson.coffee
  2. +2 −1 package.json
View
54 lib/cson.coffee
@@ -10,13 +10,13 @@ CSON =
# next(err,obj)
parseFile: (filePath,next) ->
# Read the file
- fs.readFile filePath, (err,data) =>
+ fs.readFile filePath, (err, data) =>
# Check
return next(err) if err
# Parse
dataStr = data.toString()
- @parse(dataStr,next)
+ @parse(dataStr, next)
# Chain
@
@@ -41,18 +41,20 @@ CSON =
# Parse a CSON string
- # next(err,obj)
- parse: (src,next) ->
- # Parse
- result = @parseSync(src)
-
- # Check for error
- if result instanceof Error
- # Error
- next(result)
- else
- # Success
- next(null,result)
+ # next(err, obj)
+ parse: (src, next) ->
+ setTimeout =>
+ # Parse
+ result = @parseSync(src)
+
+ # Check for error
+ if result instanceof Error
+ # Error
+ next(result)
+ else
+ # Success
+ next(null, result)
+ , 0
# Chain
@
@@ -78,17 +80,19 @@ CSON =
# Turn an object into CSON
# next(err,str)
- stringify: (obj,next) ->
- # Stringify
- result = @stringifySync(obj)
-
- # Check
- if result instanceof Error
- # Error
- next(result)
- else
- # Success
- next(null,result)
+ stringify: (obj, next) ->
+ setTimeout =>
+ # Stringify
+ result = @stringifySync(obj)
+
+ # Check
+ if result instanceof Error
+ # Error
+ next(result)
+ else
+ # Success
+ next(null, result)
+ , 0
# Chain
@
View
3 package.json
@@ -16,7 +16,8 @@
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
],
"contributors": [
- "Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
+ "Benjamin Lupton <b@lupton.cc> (http://balupton.com)",
+ "Ryan LeFevre <meltingice8917@gmail.com> (http://meltingice.net)"
],
"bugs": {
"url": "https://github.com/bevry/cson/issues"

0 comments on commit c4febc2

Please sign in to comment.
Something went wrong with that request. Please try again.