JSFiddle - React, Tailwind, and code Playground

by Marlin Forbes

CoffeeScript

processMessages = (messages, callback, args) ->
    # End it by returning the callback result when messages are done
    return callback() unless messages.length
        
    # Shift the first message off the list
    message = messages.shift()
    
    # Send it to the server for something to do
    $.ajax
        url: '/echo/json/'
        method: 'POST'
        data:
            json: JSON.stringify({ message: message, args: args })
        dataType: 'json'
        success:(data) ->
            # Respond to the server's response
            console.log 'Got ' + data.message
            
            # Process the remaining messages
            processMessages messages, callback, args

finished = ->
    console.log 'all done here'
    
processMessages ['hi', 'bob'], finished, 'yo'