Giter Site home page Giter Site logo

bulkan / async-you Goto Github PK

View Code? Open in Web Editor NEW
111.0 10.0 39.0 403 KB

Learn to use https://github.com/caolan/async in this self guided workshop

JavaScript 100.00%
async workshop rvagg javascript node looking-for-contributors looking-for-maintainer

async-you's Introduction

async-you's People

Contributors

alph486 avatar ashander avatar bulkan avatar dependabot[bot] avatar francesmcmullin avatar ianmcbull avatar impressi-web avatar jkbits1 avatar joelgallant avatar m7v avatar manonthemat avatar nishimurakaori avatar njj avatar nmarley avatar nntndfrk avatar olslash avatar orthographic-pedant avatar rodrigo-medeiros avatar tdd avatar tpxp avatar yujiangshui avatar zorigt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async-you's Issues

Exercise 3 of 7, async.each, why do we have 'return done();'?

For line 13 below where it states 'return done()', why are we using this instead of 'done()'. I assume they are equivalent. Propose to change to just done().

var http = require('http')
  , async = require('async');
async.each(['cat', 'meerkat', 'penguin'], function(item, done){
  var opts = {
    hostname: 'http://httpbin.org',
    path: '/post',
    method: 'POST'
  };
  var req = http.request(opts, function(res){
    res.on('data', function(chunk){
    });
    res.on('end', function(){
     return done();
    });
  });
  req.write(item);
  req.end();
},
function(err){
  if (err) console.log(err);
});

ECONNREFUSED 127.0.0.1:4242 in EACH exercise

My code was functionally equivalent to the official solution, but I ended up copy/pasting the official solution in an effort to debug the error. It didn't help.

var http = require('http')
  , async = require('async');

async.each(process.argv.slice(2), function(item, done){
  http.get(item, function(res){
    res.on('data', function(chunk){
    });

    res.on('end', function(){
      done(null);
    });
  }).on('error', function(err){
    done(err);
  });
},
function(err){
  if(err) console.error(err);
});
$ async-you run program.js
{ Error: connect ECONNREFUSED 127.0.0.1:4242
    at Object.exports._errnoException (util.js:1050:11)
    at exports._exceptionWithHostPort (util.js:1073:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 4242 }

Node version:

$ node -v
v7.9.0

Note that the first url (http://localhost:9345) succeeded silently as expected. It was the second url that failed with the error above.

Error in lesson whilst

Solution in solution.js does not verify, but this does

var http = require('http')
  , async = require('async');


var requestBody = '';

var count = 1;

async.whilst(
  function() {
    return !/meerkat/.test(requestBody.trim());
  },

  function(done){
    var body = '';
    http.get(process.argv[2], function(res){
      res.on('data', function(chunk){
        body += chunk.toString();
        ++count;
      });

      res.on('end', function(){
        requestBody = body;        
        done();
      });
    }).on('error', done);
  },

  function(err){
    if (err) return console.log(err);
    console.log(count);
  }
)

HTTP a little distracting

I know these are very simple examples, and do not misunderstand me by thinking I am saying they are too "difficult" or anything. But I think having the http posts and (to a lesser extent) gets distracts a bit from the exercises on async. If you miss anything, don't use those much, or even are just having an off day, you can spend a lot of time debugging http instead of dealing with the async stuff. Maybe setTimeouts or some other simple mechanism are better? Even if the expected code for the http parts were given in the instructions, it would remove a lot of extra work to get the concepts of async.

Thanks for the workshop!

async.whilst solution doesn't compile

hi!

I tried out the async.whilst challenge and I couldn't get my code or the given solution to compile. I get this error:

โžœ  async-you git:(master) async-you run whilst.js
/usr/local/lib/node_modules/async-you/exercises/whilst/exercise.js:51
  if (!this.servers.length)
                   ^
TypeError: Cannot read property 'length' of undefined
    at Exercise.<anonymous> (/usr/local/lib/node_modules/async-you/exercises/whilst/exercise.js:51:20)
    at next (/usr/local/lib/node_modules/async-you/node_modules/workshopper-exercise/exercise.js:260:17)
    at Exercise.end (/usr/local/lib/node_modules/async-you/node_modules/workshopper-exercise/exercise.js:266:5)
    at Workshopper.end (/usr/local/lib/node_modules/async-you/node_modules/workshopper/workshopper.js:191:12)
    at Workshopper.done (/usr/local/lib/node_modules/async-you/node_modules/workshopper/workshopper.js:323:19)
    at Exercise.<anonymous> (/usr/local/lib/node_modules/async-you/node_modules/workshopper-exercise/exercise.js:149:14)
    at /usr/local/lib/node_modules/async-you/node_modules/workshopper-exercise/exercise.js:136:16
    at Exercise.<anonymous> (/usr/local/lib/node_modules/async-you/node_modules/workshopper-exercise/filecheck.js:10:14)
    at FSReqWrap.oncomplete (fs.js:99:15)

Thanks!

exercise times - superfluous function?

In the times exercise, while we post 5 users i'm confused by the way we call our_adduser function.

post: function(done){
    async.times(5, function(n, next){
        _addUser(++n, function(err){
            next(err);
        });
    });
}

what does wrapping the call to next in a new function add?
_addUser(++n, next) seems to work also, it passes the verify tests.

Wrong version of this package on npm

As I can see, async-you workshop source code has Russian translation, but I can't see this language in the "choose language" menu after installing workshop globally from the npm. I guess, something wrong with versions. Could you make an update, please?

screenshots

screenshots are always very inviting and helpful :)

Series challenge

This is my code. I'm doing this in coffeescript.

http  = require 'http'
async = require 'async'
fs    = require 'fs'


f1 = (cb) ->
    cb null, process.argv[2]

f2 = (file, cb) ->
    # console.log file
    fs.readFile file, 'utf8', (err, data) ->
        if err
            cb err

        cb null, data

f3 = (link, cb) ->
    # console.log link
    body = ''

    req = http.get link, (res) ->

        res.on 'data', (chunk)->
            body += chunk.toString()

        res.on 'end', ()->
            cb null, body

    req.on 'error', (err) ->
        cb err


last = (error, result) ->
    console.log result


async.waterfall [f1, f2, f3], last

Trying to get http://localhost:3131/one I get thee following:

{ [Error: socket hang up] code: 'ECONNRESET' }

Any ideas?

Incorrect command line in the instructions?

The instructions under "Installation" in README.md say -

  1. Install Node.js
  2. Run sudo npm install async-you -g
  3. Run async_you

I followed these instructions, yet when running the command async_you it returned "command not found". However running the command async-you did work, and opened up the workshop.

I should add - Mac OS X 10.9.2 using iTerm and zsh.

Error in lesson series object

According to the problem description the solution in solution.js should work but only this solution will verify:

var http = require('http')
  , async = require('async');

async.series({
  requestOne: function(done){
    var body = '';
    http.get(process.argv[2], function(res){
      res.on('data', function(chunk){
        body += chunk.toString();
      });

      res.on('end', function(chunk){
        done(null, body);
      });
    }).on('error', function(e){
      done(e);
    });
  },
  requestTwo: function(done){
    var body = '';
    http.get(process.argv[2], function(res){
      res.on('data', function(chunk){
        body += chunk.toString();
      });

      res.on('end', function(chunk){
        done(null, body);
      });
    }).on('error', function(e){
      done(e);
    });
  }
},
function(err, result){
  if (err) return console.error(err);
  console.log(result);
});

Which requests the /one url twice instead of /one and then /two.

naming the error function in waterfall challenge

hi!

I am new to asynchronous javascript programming and I had to watch this video a couple of times to figure out how the waterfall method works.

I was unable to understand where this done(null, data) existed in the solution for waterfall challenge. It then occurred to me that "done()" is the function that is given along with the array of functions to async.waterfall. Had it been named in the solution I wouldn't have to look so hard.

Thanks.

async.waterfall([
    function(done){
        fs.readFile(process.argv[2], function(err, data){
            if (err) return done(err);
            done(null, data);
        });
    },

    function(data, done) {
        var body = '';
        http.get(data.toString().trimRight(), function(res){
            res.on('data', function(chunk){
                body += chunk.toString();
            });

            res.on('end', function(chunk){
                done(null, body);
            });
        }).on('error', function(e){
            done(e);
        });
    }
], function done(err, result){
    if (err) return console.error(err);
    console.log(result);
});

Third Exercise 'Each' Receive One Url

First instruction is

Create a program that will receive two URLs as the first and second
command-line arguments.

but there is no second command line argument and solution is about just first command line argument.

Async Series Exercise

Hello. I recently started this workshop and I think this exercise has a bug on a process object Params.

The explanation of the problem states that we will receiving two parameters. Debugging a little I realize that the process.argv[3] is undefined, and the process.argv[2] is a fle route, so is neccesary the Node FS module to read that File Route and get the URL to process the HTTP requests.

This is the code that I've been working on, when I run it there's not syntax errors, but when I verify it return empty, I don't know what else to do

var http = require('http');
var async = require('async');
var fs = require('fs');

async.series({

	requestOne: function(done){

		fs.readFile(process.argv[2], function(err,furl) {
			if(err) console.log(err);
			http.get(furl.toString(), function(res){
				res.on('data',function(err,data){
					if(err) return err;
					done(null,data.toString());
				})
			})
		})
		
	},
	requestTwo: function(done){

		fs.readFile(process.argv[3], function(err,surl) {
			if(err) console.log(err);

		 	http.get(surl.toString(), function(res){
				res.on('data',function(err,data){
					if(err) return err;
					done(null,data.toString());
				})
			})
		})
	}

}, function(err,results) {
	if(err) return err;
	console.log(results);
});

Thanks in advance, any help will be appreciated.

Each Problem: ECONNREFUSED

Pushka-3:async-school latrasis$ async-you verify each.js
Verifying "EACH"...

ACTUAL:   ""
EXPECTED: "{ [Error: connect ECONNREFUSED]"

ACTUAL:   null
EXPECTED: "  errno: 'ECONNREFUSED',"

ACTUAL:   null
EXPECTED: "  syscall: 'connect' }"

ACTUAL:   null
EXPECTED: ""

# FAIL

Your solution to EACH didn't match the expected output.
Try again!

Not super clear that there will be an error in the `each` exercise

Looking at the solution it now makes sense that one url is good and one is bad. This is a good teaching point to make sure students know how to handle errors. But it would be good to be a little more explicit that one URL will be good and one will be bad. So they make sure to handle it.
I first thought that you forgot to start a server at :4242 and was going to make a pull request with the fix. But then ran your solution and understand now. ๐Ÿ˜„

Thanks for the great course!

Having trouble with npm "async" dependency

Using a clean install of npm and async-you, I get this error when trying to run even the solution code.

$ async-you run test.js 

module.js:340
    throw err;
          ^
Error: Cannot find module 'async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/action/workspace/test.js:2:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

I was able to resolve this by doing a local npm install async, but a global install does not fix this.
Maybe this is only relevant to my install of node/npm, but I'd like to know why.

Screen shot:
screen shot 2015-04-07 at 7 09 34 pm

Whilst (lession 7) verification seems incorrect, solution seems incorrect

Hi, I think there's a couple problems with lession 7 (whilst).

I understand the problem description to be asking us to print the number of get requests required before the server returns a response body that contains the word 'meerkat'.

The server responds with 'meerkat' on the first request, but logging '1' fails verification (it is expecting '2').

Also, the solution code provided in the repo is not doing what the problem description asks. It is counting the number of 'data' events emitted which does not necessarily correspond to the number of requests performed (as a single request can result in multiple data events). This was changed in commit 699dc54 (the code was correct before this commit, where count gets incremented in the 'end' event not the 'data' event).

It also initializes count to 1, and then increments it in the data event which results in (assuming 1 data event per request) a count of 2 when only 1 request has been made.

async.times and async.reduce explanation

Is there a reason why async.times and async.reduce challenges have no explanation and asks user to read up this one on their own? While doing these challenges it works out quickly if i can read a small explanation and then proceed to solving the challenge than having to look up the docs. This is trivial in some ways to experienced users but then experienced ones wouldn't be solving these tutorials :)

times problem badly explained

the 'TIMES' problem is badly explained.

the solution requires you do an async.series and having your async.times return a value of "saved". and then you are to print this AND the response from GET /users to the output. no where in the problem is this explained.

After properly printing only the response from the GET /users and still failing I looked at the solution to see what I was doing wrong.

The problem should be updated to say use series as well as have times return a value of "saved" OR the solution should be updated to only print the response from GET /users.

Times problem - Verifying failed

I try a lot and ended up copy the solution.js (async-you/problems/times/solution.js) but with verify i get:

Verifying "TIMES"...

ACTUAL:   "{\"users\":[{\"user_id\":1},{\"user_id\":2},{\"user_id\":4},{\"user_id\":5},{\"user_id\":3},{\"user_id\":1},{\"user_id\":2},{\"user_id\":4},{\"user_id\":5},{\"user_id\":3}]}"
EXPECTED: "[ 'saved',"

ACTUAL:   ""
EXPECTED: "  '{\"users\":[{\"user_id\":1},{\"user_id\":2},{\"user_id\":4},{\"user_id\":5},{\"user_id\":3},{\"user_id\":1},{\"user_id\":2},{\"user_id\":4},{\"user_id\":5},{\"user_id\":3}]}' ]"

ACTUAL:   null
EXPECTED: ""

# FAIL

Maybe the Server give wrong answer?

New exercises

I was thinking of introducing new exercises to the module like apply and auto among other things. What do you think? I will open the respective PRs if given the go.

Impossible to verify whilst exercise

Hi all,
when I try to run (or verify) the whilst exercise the get request doesn't get any results.

This is my code

var http = require('http'),
    async = require('async'),
    url = process.argv[2]

var count = 0,
    s = ''

async.whilst(
    () => {
        return s !== 'meerkat'
    },
    (next) => {
        http.get(url, (res) => {
            console.log(res)
            count++
            var body = ''
            res.on('data', (chunk) => {
                body += chunk.toString()
            })
            res.on('end', () => {
                s = body.trim()
                next()
            })
        }).on('error', (err) => console.log(err))
    },
    (err) => {
        if(err) console.log(err)
        console.log(count)
    }
)

I try to verify the exercise with the official solution but it doesn't work anyway.
I appreciate anyone help.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.