3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TimeLineで駄目だった非同期メモ

Posted at

非同期処理をTimeLineでやっていたが、
オブジェクトが多くなってくるとやっぱりバグりだしたので、

EventEmitterとDeferredを使った発見のメモ

test.js
A = (width, height) ->
    dfr = $.Deferred()
    aa = new AA()
    aa .init()
    return dfr.promise()

B = (width, height) ->
    dfr = $.Deferred()
    bb = new BB()
    bb .init()
    return dfr.promise()

C = (width, height) ->
    dfr = $.Deferred()
    cc = new CC()
    cc .init()
    return dfr.promise()

promises = [
    A(@w, @h)
    B(@w, @h)
    C(@w, @h)
]


$.when.apply(@, promises).done (args...) =>
    a = args[0]
    b = args[1]
    c = args[2]
    @DOC_ObjectPool_Body.addChild a.movieclip
    @DOC_ObjectPool_Body.addChild b.movieclip
    @DOC_ObjectPool_Body.addChild c.actionclip
    Stage.addChild @DOC_ObjectPool_Body
    dfr.resolve a, b, c
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?