Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

child_process tests with web server

  • Loading branch information...
commit c14cc1d4a6d714677d5d68c74ae3c351539ab931 1 parent 1d11431
@epeli authored
View
41 lib/web/clientscripts/main.coffee
@@ -11,25 +11,38 @@ class JQEvenEmitter
-i = 0
-class Watcher extends JQEvenEmitter
+class WatcherOuput
- constructor: ->
- super
- @i = i += 1
- console.log "building"
+ constructor: (@name, @el) ->
+ remote = now[@name] = {}
+ remote.sendStdout = => @pushStdout.apply @, arguments
+ remote.sendStderr = => @pushStderr.apply @, arguments
+ remote.reset = => @reset()
- @on "some", => @mymethod()
+ setExitStatus: ->
+ @title.css "color", "red"
- mymethod: ->
- console.log "got some #{ @i }"
+ pushStdout: (data) ->
+ @stdout.text @stdout.text() + data
+ pushStderr: (data) ->
+ @stderr.text @stderr.text() + data
+ reset: ->
+ @stdout.text ""
+ @stderr.text ""
+ render: ->
+ @title = @el.append("<h2>#{ @name }</h2>")
+ for type in ["stdout", "stderr"]
+ id = "#{ type }-#{ @name }"
+ @[type] = $("#" + id)
+ if @[type].size() is 0
+ @["#{ type }Title"] = @el.append("<h3>#{ type }</h3>")
+ @[type] = $("<textarea>", id: id).appendTo @el
-w = new Watcher
-w.emit "some"
-w2 = new Watcher
-w2.emit "some"
-w2.emit "some"
+$ ->
+ w = new WatcherOuput "myproj:compass", $("body")
+ w.render()
+
View
23 lib/web/server.coffee
@@ -1,5 +1,7 @@
+{exec} = require "child_process"
+
express = require "express"
nowjs = require("now")
@@ -10,27 +12,22 @@ everyone = nowjs.initialize app
app.shareUrl "/nowjs/now.js"
-app.exec ->
- now.renderOutput = (watcher) ->
- console.log "got", watcher.name
- textarea = $("##{ watcher.name }")
- if textarea.size() is 0
- textarea = $("<textarea>", id: "foo").appendTo("body")
-
+i = 1
+renderApp = (req, res) ->
+ res.render "index.jade", text: "hello jade"
+ name = "myproj:compass"
-setTimeout ->
- everyone.now.renderOutput name: "myproj:compass"
-,
- 2000
+ cmd = exec "slow"
+ cmd.stdout.on "data", (data) -> process.stdout.write(data)
+ cmd.stdout.on "data", (data) ->
+ everyone.now[name].sendStdout(data)
-renderApp = (req, res) ->
- res.render "index.jade", text: "hello jade"
app.get "/", renderApp
View
1  package.json
@@ -14,6 +14,7 @@
, "watch": ""
, "findit": ""
, "iniparser": ""
+ , "underscore": ""
, "gex": ""
, "express": ""
, "jade": ""
Please sign in to comment.
Something went wrong with that request. Please try again.