h2non/thread.js

View on GitHub
examples/bind-functions.html

Summary

Maintainability
Test Coverage
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script src="../thread.js"></script>
    <script>
      var worker = thread({
        env: {
          x: 2,
          defer: function (fn) {
            setTimeout(fn, 1)
          }
        }
      })

      var task = worker.run(function (done) {
        var sum = env.x * 2
        env.defer(function () {
          done(null, sum)
        }, 250)
      }).then(function (value) {
        console.log('Result:', value)
      })

      task['finally'](function (result) {
        console.log('Finally:', result)
      })
    </script>
  </body>
</html>