Skip to content

Commit

Permalink
Web Workers: test messaging with addEventListener
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Jul 6, 2018
1 parent 343782b commit a4b0545
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/WebSharper.Html5.Tests/Tests.fs
Expand Up @@ -473,12 +473,16 @@ let WebWorkerTests =
equal res "The worker replied: [worker] Hello world!"

let worker2 = new Worker(fun self ->
self.Onmessage <- fun e ->
self.PostMessage(GlobalFunction2(As<string> e.Data))
self.AddEventListener("message", (fun (e: Dom.Event) ->
let e = e :?> MessageEvent
self.PostMessage(GlobalFunction2(As<string> e.Data))
), false)
)
let! res = AsyncContinuationTimeout "Worker didn't run" <| fun ok ->
worker2.Onmessage <- fun e ->
ok ("The worker replied: " + As<string> e.Data)
worker2.AddEventListener("message", (fun (e: Dom.Event) ->
let e = e :?> MessageEvent
ok ("The worker replied: " + As<string> e.Data)
), false)
worker2.PostMessage "Hello world!"
equal res "The worker replied: [worker2] Hello world!"
}
Expand Down

0 comments on commit a4b0545

Please sign in to comment.