Skip to content

Commit

Permalink
Group together post worker creation commands.
Browse files Browse the repository at this point in the history
on ser server input in worker if we have settings for it
  • Loading branch information
amasad committed Apr 8, 2012
1 parent f78eba8 commit 5ee0a0b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,29 @@ class Sandbox extends EventEmitter
load: (moreScripts, workerFriendly=true) ->
allScripts = @baseScripts.concat moreScripts
base = allScripts.shift()
# Orders worker to start importing scripts.
startImport = => @post type: 'importScripts', data: allScripts
# Kill existing worker if we have one.
if @worker? then @kill()

# Called after creating the worker.
postCreate = =>
@post type: 'importScripts', data: allScripts
if @input_server?
@post type: 'set_input_server', data: @input_server

if not workerSupported or not workerFriendly
# Worker not supported; create a new iframe sandbox replacing the old one.
@loader.createSandbox (sandbox) =>
@worker = sandbox
@workerIsIframe = true
window.removeEventListener 'message', @onmsg, false
window.addEventListener 'message', @onmsg, false
startImport()
@post type: 'set_input_server', data: @input_server
postCreate()
else
# Workers are supported! \o/
@worker = new Worker base
@workerIsIframe = false
@worker.addEventListener 'message', @onmsg, false
startImport()
@post type: 'set_input_server', data: @input_server
postCreate()

post: (msgObj) ->
msgStr = JSON.stringify msgObj
Expand Down

0 comments on commit 5ee0a0b

Please sign in to comment.