1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495# 1 "src/lib/eliom_react.client.ml"openLwt.Syntax(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010-2011
* Raphaël Proust
* Pierre Chambart
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)(* Module for event unwrapping *)openLwt_reactopenLwt.Infixletsection=Logs.Src.create"eliom:comet"moduleDown=structtype'at='aReact.E.tlethandle_react_exn,set_handle_react_exn_function=letpp_exn_optionppf=function|Someexn->Format.fprintfppf"@\n%s"(Printexc.to_stringexn)|None->()inletr=ref(fun?exn()->lets="Exception during comet with react. Customize this with Eliom_react.set_handle_react_exn_function. "inLogs.msg~src:sectionLogs.Debug(funfmt->fmt"%s%a"spp_exn_optionexn);Lwt.return_unit)in(fun~exn()->!r~exn()),funf->r:=fletinternal_unwrap(channel,_unwrapper)=(* We want to catch more exceptions here than the usual exceptions caught
in Eliom_comet. For example Channel_full. *)(* We transform the stream into a stream with exception: *)letstream=Lwt_stream.wrap_exnchannelinLwt.async(fun()->Lwt_stream.iter_s(function|Errorexn->let*()=handle_react_exn~exn()inLwt.failexn|Ok()->Lwt.return_unit)stream);E.of_streamchannellet()=Eliom_unwrap.register_unwrapperEliom_common.react_down_unwrap_idinternal_unwrapendmoduleUp=structtype'at='a->unitLwt.tletinternal_unwrap(service,_unwrapper)x=Eliom_client.call_service~service()x>|=fun_->()let()=Eliom_unwrap.register_unwrapperEliom_common.react_up_unwrap_idinternal_unwrapendmoduleS=structmoduleDown=structtype'at='aReact.S.tletinternal_unwrap(channel,value,_unwrapper)=lete=E.of_streamchannelinS.hold~eq:(fun__->false)valueelet()=Eliom_unwrap.register_unwrapperEliom_common.signal_down_unwrap_idinternal_unwrapendendletforce_link=()