 bondscell_results$5d2b13be-3d35-11eb-2e47-51223a2a47bfqueued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAm1persist_js_state·has_pluto_hook_features§cell_id$5d2b13be-3d35-11eb-2e47-51223a2a47bfdepends_on_disabled_cells§runtime .Tpublished_object_keysdepends_on_skipped_cells§errored$fac02af2-3d34-11eb-17b8-61505c641f17queued¤logslinemsgHellotext/plaincell_id$fac02af2-3d34-11eb-17b8-61505c641f17kwargsrand()0.3362369120617531text/plainidMain_workspace#2_a49d2178filej/home/runner/work/disorganised-mess/disorganised-mess/throttled.jl#==#dde97532-3d34-11eb-030d-054b47086952groupthrottledlevelInforunning¦outputbodymimetext/plainrootassigneelast_run_timestampAm~persist_js_state·has_pluto_hook_features§cell_id$fac02af2-3d34-11eb-17b8-61505c641f17depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$880ba494-3b1f-4d1d-95b4-469a7178726cqueued¤logsrunning¦outputbody9<div class="markdown"><h1>With cooldown delay</h1>
</div>mimetext/htmlrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$880ba494-3b1f-4d1d-95b4-469a7178726cdepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$8f92a451-694f-41e3-8483-61b7fd26e3ebqueued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAj0persist_js_state·has_pluto_hook_features§cell_id$8f92a451-694f-41e3-8483-61b7fd26e3ebdepends_on_disabled_cells§runtime Dpublished_object_keysdepends_on_skipped_cells§errored$0aec4a64-3d35-11eb-3d3b-a306558f610cqueued¤logsrunning¦outputbody0.03041815757751465mimetext/plainrootassigneelast_run_timestampAm@ܰpersist_js_state·has_pluto_hook_features§cell_id$0aec4a64-3d35-11eb-3d3b-a306558f610cdepends_on_disabled_cells§runtimeГpublished_object_keysdepends_on_skipped_cells§errored$bf71daae-3d34-11eb-1ca1-d9b018e99f18queued¤logsrunning¦outputbody<div class="pluto-docs-binding">
<span id="throttled">throttled</span>
<div class="markdown"><p>Create a throttled function, which calls the given function <code>f</code> at most once per given interval <code>max_delay</code>.</p>
<p>It is <em>leading</em> &#40;<code>f</code> is invoked immediately&#41; and <em>not trailing</em> &#40;calls during a cooldown period are ignored&#41;.</p>


</div>
</div>
mimetext/htmlrootassigneelast_run_timestampAlpersist_js_state·has_pluto_hook_features§cell_id$bf71daae-3d34-11eb-1ca1-d9b018e99f18depends_on_disabled_cells§runtime `dpublished_object_keysdepends_on_skipped_cells§errored$dde97532-3d34-11eb-030d-054b47086952queued¤logsrunning¦outputbody$log (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAlqpersist_js_state·has_pluto_hook_features§cell_id$dde97532-3d34-11eb-030d-054b47086952depends_on_disabled_cells§runtime kҬpublished_object_keysdepends_on_skipped_cells§errored$8a1a1300-5f32-445b-8ead-53e700fa186cqueued¤logsrunning¦outputbody8<div class="pluto-docs-binding">
<span id="throttled2">throttled2</span>
<div class="markdown"><p>Create a throttled function, which calls the given function <code>f</code> at most once per given interval <code>max_delay</code>.</p>
<p>It is <em>leading</em> &#40;<code>f</code> is invoked immediately&#41; and <em>not trailing</em> &#40;calls during a cooldown period are ignored&#41;.</p>
<p>An optional third argument sets an initial cooldown period, default is <code>0</code>. With a non-zero value, the throttle is no longer <em>leading</em>.</p>


</div>
</div>
mimetext/htmlrootassigneelast_run_timestampAm@persist_js_state·has_pluto_hook_features§cell_id$8a1a1300-5f32-445b-8ead-53e700fa186cdepends_on_disabled_cells§runtime ˕published_object_keysdepends_on_skipped_cells§errored$55752812-3d35-11eb-3962-91f60f0b8219queued¤logsrunning¦outputbody##1 (generic function with 1 method)mimetext/plainrootassigneetlast_run_timestampAm0persist_js_state·has_pluto_hook_features§cell_id$55752812-3d35-11eb-3962-91f60f0b8219depends_on_disabled_cells§runtimeGڵpublished_object_keysdepends_on_skipped_cells§errored$8872d171-f63f-4f8f-a17a-19d05e6382c4queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAjְpersist_js_state·has_pluto_hook_features§cell_id$8872d171-f63f-4f8f-a17a-19d05e6382c4depends_on_disabled_cells§runtime ǵpublished_object_keysdepends_on_skipped_cells§errored±cell_dependencies$5d2b13be-3d35-11eb-2e47-51223a2a47bfprecedence_heuristic	cell_id$5d2b13be-3d35-11eb-2e47-51223a2a47bfdownstream_cells_mapupstream_cells_mapt$55752812-3d35-11eb-3962-91f60f0b8219$fac02af2-3d34-11eb-17b8-61505c641f17precedence_heuristic	cell_id$fac02af2-3d34-11eb-17b8-61505c641f17downstream_cells_mapupstream_cells_maplog$dde97532-3d34-11eb-030d-054b47086952$880ba494-3b1f-4d1d-95b4-469a7178726cprecedence_heuristic	cell_id$880ba494-3b1f-4d1d-95b4-469a7178726cdownstream_cells_mapupstream_cells_map@md_strgetindex$8f92a451-694f-41e3-8483-61b7fd26e3ebprecedence_heuristic	cell_id$8f92a451-694f-41e3-8483-61b7fd26e3ebdownstream_cells_mapupstream_cells_map$0aec4a64-3d35-11eb-3d3b-a306558f610cprecedence_heuristic	cell_id$0aec4a64-3d35-11eb-3d3b-a306558f610cdownstream_cells_mapupstream_cells_map-timesqrt$bf71daae-3d34-11eb-1ca1-d9b018e99f18precedence_heuristic	cell_id$bf71daae-3d34-11eb-1ca1-d9b018e99f18downstream_cells_mapthrottled$55752812-3d35-11eb-3962-91f60f0b8219upstream_cells_map@doctimeTuple#___this_pluto_module_nameFunctionnothingReal->=+Union$dde97532-3d34-11eb-030d-054b47086952precedence_heuristic	cell_id$dde97532-3d34-11eb-030d-054b47086952downstream_cells_maplog$fac02af2-3d34-11eb-17b8-61505c641f17$55752812-3d35-11eb-3962-91f60f0b8219upstream_cells_mapBase.CoreLogging.===#___this_pluto_module_namerandBase.CoreLogging.handle_messageBase.CoreLogging.!Base#Base.CoreLogging._invoked_shouldlog@infoBase.CoreLogging.logging_errorBase.CoreLogging.>='Base.CoreLogging.current_logger_for_envBase.CoreLogging.convert$8a1a1300-5f32-445b-8ead-53e700fa186cprecedence_heuristic	cell_id$8a1a1300-5f32-445b-8ead-53e700fa186cdownstream_cells_mapthrottled2upstream_cells_map@doctimeTuple#___this_pluto_module_nameFunctionnothingReal->=+Union$55752812-3d35-11eb-3962-91f60f0b8219precedence_heuristic	cell_id$55752812-3d35-11eb-3962-91f60f0b8219downstream_cells_mapt$5d2b13be-3d35-11eb-2e47-51223a2a47bfupstream_cells_maplog$dde97532-3d34-11eb-030d-054b47086952throttled$bf71daae-3d34-11eb-1ca1-d9b018e99f18$8872d171-f63f-4f8f-a17a-19d05e6382c4precedence_heuristic	cell_id$8872d171-f63f-4f8f-a17a-19d05e6382c4downstream_cells_mapupstream_cells_mapcell_execution_order$bf71daae-3d34-11eb-1ca1-d9b018e99f18$dde97532-3d34-11eb-030d-054b47086952$fac02af2-3d34-11eb-17b8-61505c641f17$55752812-3d35-11eb-3962-91f60f0b8219$5d2b13be-3d35-11eb-2e47-51223a2a47bf$0aec4a64-3d35-11eb-3d3b-a306558f610c$880ba494-3b1f-4d1d-95b4-469a7178726c$8a1a1300-5f32-445b-8ead-53e700fa186c$8872d171-f63f-4f8f-a17a-19d05e6382c4$8f92a451-694f-41e3-8483-61b7fd26e3eblast_hot_reload_time        shortpaththrottled.jlprocess_statusreadypathB/home/runner/work/disorganised-mess/disorganised-mess/throttled.jlpluto_versionv0.19.47last_save_timeAjϐcell_order$bf71daae-3d34-11eb-1ca1-d9b018e99f18$dde97532-3d34-11eb-030d-054b47086952$fac02af2-3d34-11eb-17b8-61505c641f17$55752812-3d35-11eb-3962-91f60f0b8219$5d2b13be-3d35-11eb-2e47-51223a2a47bf$0aec4a64-3d35-11eb-3d3b-a306558f610c$880ba494-3b1f-4d1d-95b4-469a7178726c$8a1a1300-5f32-445b-8ead-53e700fa186c$8872d171-f63f-4f8f-a17a-19d05e6382c4$8f92a451-694f-41e3-8483-61b7fd26e3ebpublished_objectsnbpkginstall_time_nsΞȝinstantiatedòinstalled_versionsterminal_outputsnbpkg_sync
[0m[1mInstantiating...[22m
[90m===[39m
[32m[1m  No Changes[22m[39m to `/tmp/jl_EyBhs3/Project.toml`
[32m[1m  No Changes[22m[39m to `/tmp/jl_EyBhs3/Manifest.toml`

[0m[1mResolving...[22m
[90m===[39m
[32m[1m  No Changes[22m[39m to `/tmp/jl_EyBhs3/Project.toml`
[32m[1m  No Changes[22m[39m to `/tmp/jl_EyBhs3/Manifest.toml`

[0m[1mPrecompiling...[22m
[90m===[39m
[32m[1m  Activating[22m[39m new project at `/tmp/jl_EyBhs3`enabled÷restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputs$5d2b13be-3d35-11eb-2e47-51223a2a47bfcell_id$5d2b13be-3d35-11eb-2e47-51223a2a47bfcodet()metadatashow_logsèdisabled®skip_as_script«code_folded$fac02af2-3d34-11eb-17b8-61505c641f17cell_id$fac02af2-3d34-11eb-17b8-61505c641f17codelog()metadatashow_logsèdisabled®skip_as_script«code_folded$880ba494-3b1f-4d1d-95b4-469a7178726ccell_id$880ba494-3b1f-4d1d-95b4-469a7178726ccodemd"""
# With cooldown delay
"""metadatashow_logsèdisabled®skip_as_script«code_folded$8f92a451-694f-41e3-8483-61b7fd26e3ebcell_id$8f92a451-694f-41e3-8483-61b7fd26e3ebcodemetadatashow_logsèdisabled®skip_as_script«code_folded$0aec4a64-3d35-11eb-3d3b-a306558f610ccell_id$0aec4a64-3d35-11eb-3d3b-a306558f610ccode1let
	a = time()
	b = sqrt.([200])
	time() - a
endmetadatashow_logsèdisabled®skip_as_script«code_folded$bf71daae-3d34-11eb-1ca1-d9b018e99f18cell_id$bf71daae-3d34-11eb-1ca1-d9b018e99f18code"Create a throttled function, which calls the given function `f` at most once per given interval `max_delay`.

It is _leading_ (`f` is invoked immediately) and _not trailing_ (calls during a cooldown period are ignored)."
function throttled(f::Function, max_delay::Real, initial_offset::Real=0)
	local last_run_at = time() - max_delay + initial_offset
	# return f
	() -> begin
		now = time()
		if now - last_run_at >= max_delay
			f()
			last_run_at = now
		end
		nothing
	end
endmetadatashow_logsèdisabled®skip_as_script«code_folded$dde97532-3d34-11eb-030d-054b47086952cell_id$dde97532-3d34-11eb-030d-054b47086952code(function log()
	@info "Hello" rand()
endmetadatashow_logsèdisabled®skip_as_script«code_folded$8a1a1300-5f32-445b-8ead-53e700fa186ccell_id$8a1a1300-5f32-445b-8ead-53e700fa186ccodej"Create a throttled function, which calls the given function `f` at most once per given interval `max_delay`.

It is _leading_ (`f` is invoked immediately) and _not trailing_ (calls during a cooldown period are ignored).

An optional third argument sets an initial cooldown period, default is `0`. With a non-zero value, the throttle is no longer _leading_."
function throttled2(f::Function, max_delay::Real, initial_offset::Real=0)
	local last_run_at = time() - max_delay + initial_offset
	# return f
	() -> begin
		now = time()
		if now - last_run_at >= max_delay
			f()
			last_run_at = now
		end
		nothing
	end
endmetadatashow_logsèdisabled®skip_as_script«code_folded$55752812-3d35-11eb-3962-91f60f0b8219cell_id$55752812-3d35-11eb-3962-91f60f0b8219codet = throttled(log, 2, 5)metadatashow_logsèdisabled®skip_as_script«code_folded$8872d171-f63f-4f8f-a17a-19d05e6382c4cell_id$8872d171-f63f-4f8f-a17a-19d05e6382c4codemetadatashow_logsèdisabled®skip_as_script«code_folded«notebook_id$f31b129a-4a9e-11f0-149a-1db46dd1d071in_temp_dir¨metadata