Skip to content

Instantly share code, notes, and snippets.

@EdJ
Created January 23, 2014 16:02
Show Gist options
  • Save EdJ/2eed46430a9d184c0fef to your computer and use it in GitHub Desktop.
Save EdJ/2eed46430a9d184c0fef to your computer and use it in GitHub Desktop.
Short example of something I'm a bit confused about in the current implementation of Asynquence's map() implementation.
var ASQ = require('asynquence');
require('asynquence-contrib');
var returnsArr = function returnsArr(c) { c && c([1]); return [1]};
ASQ().map(returnsArr(), function (v, c) { c(v + 1) }); // fine
ASQ().then(returnsArr).map(function (v, c) { c(v + 1) }); // doesn't work
@getify
Copy link

getify commented Jan 23, 2014

You could also do:

ASQ()
.val(function(){
   return [1,2,3]; // inject a value-message into the stream
})
.seq(function(arr){
   return ASQ()
   .map(arr, function (v, c) { c(v + 1) });
})
.val(function(newArr){
   console.log(newArr); // 2,3,4
});

And of course, if that was a common use-case for you, it'd be pretty trivial to make that usage of the API into a simple plugin. Almost any usage of the ASQ API can be rolled into a plugin.

@getify
Copy link

getify commented Jan 24, 2014

After thinking it over, I decided to update map(..) itself to handle this use-case. Was a simple addition and there was no need for a separate plugin.

Thanks for the idea! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment