Skip to content

Commit

Permalink
fixed readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bvarga committed Jan 16, 2013
1 parent c70d293 commit c665e1c
Showing 1 changed file with 102 additions and 101 deletions.
203 changes: 102 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,119 +186,120 @@ Monitoring Sockets ( just available in `v3.2.2`)
with parameters, or create your own descendent class and override the `DoExecute` method.

- Creating a detached thread.

procedure TMyClass.DetachedProc( args: Pointer; context: TZMQContext; terminated: PBoolean );
var
socket: TZMQSocket;
begin
socket := context.Socket( TZMQSocketType( Args^ ) );
Dispose( args );
end;
var
thr: TZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;
thr := TZMQThread.CreateDetached( DetachedProc, sockettype );
thr.FreeOnTerminate := true;
thr.Resume;
end;

procedure TMyClass.DetachedProc( args: Pointer; context: TZMQContext; terminated: PBoolean );
var
socket: TZMQSocket;
begin
socket := context.Socket( TZMQSocketType( Args^ ) );
Dispose( args );
end;
var
thr: TZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;
thr := TZMQThread.CreateDetached( DetachedProc, sockettype );
thr.FreeOnTerminate := true;
thr.Resume;
end;
or

// create descendant class
TMyZMQThread = class( TZMQThread )
protected
procedure doExecute; override;
end;

procedure TMyZMQThread.doExecute
var
socket: TZMQSocket;
begin
// do something cool.
socket := Context.socket( TZMQSocketType(Args^) );
end;

var
myThread: TMyZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;

// the nil context means it will be a detached thread.
myThread := TMyZMQThread.Create( sockettype, nil );
myThread.Resume;
end;


- Creating an attached thread.

procedure TMyClass.AttachedProc( args: Pointer; context: TZMQContext; pipe: TZMQSocket; terminated: PBoolean );
var
socket: TZMQSocket;
msg: Utf8String;
begin
while not Terminated and not context.Terminated do
// create descendant class
TMyZMQThread = class( TZMQThread )
protected
procedure doExecute; override;
end;

procedure TMyZMQThread.doExecute
var
socket: TZMQSocket;
begin
// do some cool stuff.
// do something cool.
socket := Context.socket( TZMQSocketType(Args^) );
end;

var
myThread: TMyZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;

// you can use pipe to communicate.
pipe.recv( msg );
// the nil context means it will be a detached thread.
myThread := TMyZMQThread.Create( sockettype, nil );
myThread.Resume;
end;
end;

var
thr: TZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;
thr := TZMQThread.CreateAttached( AttachedProc, context, sockettype );
thr.FreeOnTerminate := true;
thr.Resume;


- Creating an attached thread.

procedure TMyClass.AttachedProc( args: Pointer; context: TZMQContext; pipe: TZMQSocket; terminated: PBoolean );
var
socket: TZMQSocket;
msg: Utf8String;
begin
while not Terminated and not context.Terminated do
begin
// do some cool stuff.
socket := Context.socket( TZMQSocketType(Args^) );

// you can use pipe to communicate.
pipe.recv( msg );
end;
end;

var
thr: TZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;
thr := TZMQThread.CreateAttached( AttachedProc, context, sockettype );
thr.FreeOnTerminate := true;
thr.Resume;

// use thr.pipe to send stuff to the thread.
thr.pipe.send( 'hello thread' );
end;
// use thr.pipe to send stuff to the thread.
thr.pipe.send( 'hello thread' );
or

// create descendant class
TMyZMQThread = class( TZMQThread )
protected
procedure doExecute; override;
end;

procedure TMyZMQThread.doExecute
var
socket: TZMQSocket;
msg: Utf8String;
begin
// do something cool.
socket := Context.socket( TZMQSocketType(Args^) );
while true do

// create descendant class
TMyZMQThread = class( TZMQThread )
protected
procedure doExecute; override;
end;

procedure TMyZMQThread.doExecute
var
socket: TZMQSocket;
msg: Utf8String;
begin
pipe.recv( msg );
// do something cool.
socket := Context.socket( TZMQSocketType(Args^) );
while true do
begin
pipe.recv( msg );
end;
end;
end;

var
myThread: TMyZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;

myThread := TMyZMQThread.Create( sockettype, context )
myThread.Resume;

myThread.pipe.send( 'Hello thread' );
end;
var
myThread: TMyZMQThread;
sockettype: ^TZMQSocketType;
begin
New( sockettype );
sockettype^ := stDealer;

myThread := TMyZMQThread.Create( sockettype, context )
myThread.Resume;
myThread.pipe.send( 'Hello thread' );
end;

Examples
========
Expand Down

0 comments on commit c665e1c

Please sign in to comment.