Skip to content

Commit

Permalink
change promises to event-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
AntouanK committed Jul 12, 2014
1 parent d8d7f9f commit cc0c5c7
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions docs/recipes/make-stream-from-memory-contents.md
Expand Up @@ -48,7 +48,7 @@ var gulp = require('gulp'),
concat = require('gulp-concat'),
size = require('gulp-size'),
path = require('path'),
Q = require('q');
es = require('event-stream');

var memory = {}; // we'll keep our assets in memory

Expand Down Expand Up @@ -84,23 +84,20 @@ gulp.task('write-versions', function(){
// we store all the different version file names in an array
var availableVersions = Object.keys(memory.versions),
// we make an array to store all the stream promises
streamPromises = [];
streams = [];

availableVersions
.forEach(function(v){

// make a promise for that version-stream
var deferred = Q.defer();
// add it to the promises array
streamPromises.push(deferred);

// make a new stream with fake file name
var stream = source('final.' + v ),
// we load the data from the concatenated libs
fileContents = memory['libs.concat.js'] +
// we add the version's data
'\n' + memory.versions[v];

streams.push(stream);

// write the file contents to the stream
stream.write(fileContents);

Expand All @@ -113,13 +110,10 @@ gulp.task('write-versions', function(){
// transform the raw data into the stream, into a vinyl object/file
.pipe( vinylBuffer() )
//.pipe( tap(function(file){ /* do something with the file contents here */ }) )
.pipe( gulp.dest('./output') )
.on('end', function(){
deferred.resolve();
});
.pipe( gulp.dest('./output') );
});

return streamPromises;
return es.merge.apply(this, streams);

});

Expand Down

0 comments on commit cc0c5c7

Please sign in to comment.