InteractiveAdvertisingBureau / SIMID

Secure Interactive Media Interface Definition (SIMID)
https://interactiveadvertisingbureau.github.io/SIMID/
Apache License 2.0
46 stars 25 forks source link

Refactors promises to be more simple to read #352

Closed ryanthompson591 closed 4 years ago

ryanthompson591 commented 4 years ago

The new workflow introduces 2 promises:

  1. sessionCreatedPromise_ that resolves when the simid creative initializes a session.
  2. resolveInitializationPromise_ that resolves when initialization is resolved.

The workflow should be:

  1. Creative creates a session.
  2. Player calls SIMID:player:Init
  3. Creative calls SIMID:Player:startCreative

However, these are all asynchronous so they may be called out of order. In order to keep these in order, this sample code uses promises.

Calling Init will

  1. wait for the session to be created (via sessionCreatedPromise_)
  2. then call SIMID:player:init

Calling playAd will:

  1. Wait for the creative to respond to the initialization message (via resolveInitializationPromise_)
  2. then call SIMID:player:startCreative