Defining TypeScript callback type

I just found something in the TypeScript language specification, it’s fairly easy. I was pretty close. the syntax is the following: public myCallback: (name: type) => returntype; In my example, it would be class CallbackTest { public myCallback: () => void; public doWork(): void { //doing some work… this.myCallback(); //calling callback } } As a … Read more

How to sync JavaScript callbacks?

The good news is that JavaScript is single threaded; this means that solutions will generally work well with “shared” variables, i.e. no mutex locks are required. If you want to serialize asynch tasks, followed by a completion callback you could use this helper function: function serializeTasks(arr, fn, done) { var current = 0; fn(function iterate() … Read more

Pass an Objective-C object to a function as a void * pointer

Do something like this: void func(void *q) { NSObject* o = CFBridgingRelease(q); NSLog(@”%@”, o); } int main(int argc, const char * argv[]) { @autoreleasepool { NSObject* o = [NSObject new]; func((void*)CFBridgingRetain(o)); } return 0; } Note that CFBridgingRetain() and CFBridgingRelease() are macros around compiler attributes. Feel free to use either. I like the API variant … Read more

Does an async function always need to be called with await?

It is not necessary if your logic doesn’t require the result of the async call. Although not needed in your case, the documentation lists two benefits to having that warning enabled: While this is generally not necessary, it gives two main benefits. The first one is that you won’t forget to add ‘await’ when surrounding … Read more

c++ Implementing Timed Callback function

For a portable solution, you can use boost::asio. Below is a demo I wrote a while ago. You can change t.expires_from_now(boost::posix_time::seconds(1)); to suit you need say make function call after 200 milliseonds. t.expires_from_now(boost::posix_time::milliseconds(200)); Below is a complete working example. It’s calling repeatedly but I think it should be easy to call only once by just … Read more