Brendan Eich (2013-12-13T07:43:58.000Z)
Grrr, something stripped leading spaces. Trying again.

/be

-----

<https://gist.github.com/>


  public
  disnet <https://gist.github.com/disnet> / *let_async.js
  <https://gist.github.com/disnet/7934003>*
  Last active 3 hours ago

sweet.js: async macro

  * Gist Detail <https://gist.github.com/disnet/7934003>
  * Revisions 4 <https://gist.github.com/disnet/7934003/revisions>
  * Stars 4 <https://gist.github.com/disnet/7934003/stars> 

  *


  * *Clone* this gist
  * *Embed* this gist
  * *Link to* this gist 

*let_async.js*
JavaScript

  * <https://gist.github.com/disnet/7934003#file-let_async-js>
  * <https://gist.github.com/disnet/7934003/raw/171bc2ee9d1ea6f236a7376e2a1835e0067df009/let_async.js>

let let = macro {
rule { async $vars ... = $fname ... ($params ...); $rest ...} => {
$fname ... ($params ..., function (err, $vars ...) {
if (err) throw err;
$rest ...
})
}
}
var buffer = new Buffer(1024);
let async infile = fs.open("/tmp/in.txt");
let async outfile = fs.open("/tmp/out.txt");
let async bytesRead, buffer = fs.read(infile, buffer, 0, 1024, 0);
let async bytesWritten, buffer = fs.write(outfile, buffer, 0, 1024, 0);
console.log("We read " + bytesRead + " bytes and wrote " + bytesWritten 
+ " bytes.");
// compiles to:
var buffer$188 = new Buffer(1024);
fs.open('/tmp/in.txt', function (err$190, infile$191) {
if (err$190)
throw err$190;
fs.open('/tmp/out.txt', function (err$193, outfile$194) {
if (err$193)
throw err$193;
fs.read(infile$191, buffer$188, 0, 1024, 0, function (err$196, 
bytesRead$197, buffer$188) {
if (err$196)
throw err$196;
fs.write(outfile$194, buffer$188, 0, 1024, 0, function (err$200, 
bytesWritten$201, buffer$188) {
if (err$200)
throw err$200;
console.log('We read ' + bytesRead$197 + ' bytes and wrote ' + 
bytesWritten$201 + ' bytes.');
});
});
});
});

Please sign in <https://gist.github.com/login?return_to=/disnet/7934003> 
to comment on this gist.

© 2013 GitHub Inc. All rights reserved.

<https://gist.github.com/>

  * The GitHub Blog <https://github.com/blog>
  * Support <mailto:support at github.com>
  * Contact <https://github.com/contact>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131212/18d56227/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c347b975e43c0d01474d7b64d4d1aa99
Type: image/jpeg
Size: 5546 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131212/18d56227/attachment-0001.jpe>
forbes at lindesay.co.uk (2013-12-16T15:13:02.106Z)
duplicate message
forbes at lindesay.co.uk (2013-12-16T15:12:33.797Z)