test_that(
"1.1 Event loop phases are run in the correct order.",
code = {
phase_tracker <- list()
track_phases <- function() {
append_to_tracker <- function(phase) {
phase_tracker <<- append(phase_tracker, phase)
}
.add_to_callback(function() append_to_tracker(.event_loop$current_phase))
.add_to_close(function() append_to_tracker(.event_loop$current_phase))
set_timeout(function() append_to_tracker(.event_loop$current_phase), 0)
.add_to_poll(function() append_to_tracker(.event_loop$current_phase))
set_immediate(function() append_to_tracker(.event_loop$current_phase))
}
track_phases()
while (length(phase_tracker) != 5) {
later::run_now()
}
expect_true(identical(phase_tracker[[1]], .event_loop$loops$timer))
expect_true(identical(phase_tracker[[2]], .event_loop$loops$callback))
expect_true(identical(phase_tracker[[3]], .event_loop$loops$poll))
expect_true(identical(phase_tracker[[4]], .event_loop$loops$check))
expect_true(identical(phase_tracker[[5]], .event_loop$loops$close))
}
)
test_that(
"1.2 Next tick appropriately goes to next phase",
code = {
next_phase_poll <- FALSE
# next tick phase should be .next_tick_poll
.add_to_poll(function() {
next_tick(
function() {
next_phase_poll <<- {
identical(.event_loop$current_phase, .event_loop$loops$check)
}
}
)
}
)
wait_for_change("next_phase_poll", FALSE)
expect_true(next_phase_poll)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.