OpenersNotesSection(Spacer1)Details

Use MLWaitForLinkActivityWithCallback() on a background thread that needs to wait for data in order not to block any user interface or main threads of the application.

Use MLWaitForLinkActivityWithCallback() (or the related function (NonWLLink[MLWaitForLinkActivity(), paclet:/ref/c/MLWaitForLinkActivity])) when needing to wait for link activity on a link that is enabled for logging.

MLWaitForLinkActivityWithCallback() returns MLWAITERROR in the event of an error and MLWAITSUCCESS if the function succeeds.

(NonWLLink[MLLinkWaitCallBackObject, paclet:ref/c/MLLinkWaitCallBackObject]) is a pointer to a function of the form int function(MLINK, void *). The second argument is reserved for future use. If the function returns 1, MLWaitForLinkActivityWithCallback() will return MLWAITCALLBACKABORTED.

MWaitForLinkActivityWithCallback() is declared in the MathLink header file (RefLink[mathlink.h, paclet:/ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "mathlink.h"

/* A function for MathLink to call back to while waiting */
int WaitFunction(MLINK l, void *future)
{
	/* By default do not back out of 
		MLWaitForLinkActivityWithCallback(). */
	return 0;
}


/* A function for waiting for link activity */

void f(MLINK l)
{
	switch(MLWaitForLinkActivityWithCallBack(l, WaitFunction))
	{
		case MLWAITERROR:
			/* Handle the error */
			break;
		case MLWAITSUCCESS:
			/* Now read incoming data */
			break;
		case MLWAITCALLBACKABORTED:
		default:
			/* WaitFunction decided to abort the wait. */
	}
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLWaitForLinkActivity(), paclet:/ref/c/MLWaitForLinkActivity])  ▪  (NonWLLink[MLLogStreamToFile(), paclet:/ref/c/MLLogStreamToFile])}})}})