Skip to content

Instantly share code, notes, and snippets.

View Altair200333's full-sized avatar

Mike Petrenko Altair200333

View GitHub Profile
@Altair200333
Altair200333 / idisposable.js
Created October 29, 2023 07:29
IDisposable example in JS. for objects derived from IDisposable `dispose` will be called when instance of your object is reclaimed by GC.
const disposeObjectCallback = (dispose) => {
dispose();
}
const registry = new FinalizationRegistry(disposeObjectCallback);
const registerDisposable = (instance) => {
if (instance instanceof IDisposable) {
// register weak reference to instance and pass dispose function as callback
registry.register(new WeakRef(instance), instance._disposeCallback);
@Altair200333
Altair200333 / SyncTimerDispatcher.cs
Last active January 13, 2022 09:49
SyncTimerDispatcher executes specified method on the UI thread every [ms] milliseconds
namespace audioTest
{
//Executes specified method on the UI thread every [ms] milliseconds
class SyncTimerDispatcher
{
public delegate void TickDelegate();
//Your custom function to be called periodically
public TickDelegate TickHandler;