2018-01-10 19:31:02 +03:00
|
|
|
-- Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- This source code is distributed under the terms of a BSD license,
|
|
|
|
-- found in the LICENSE file.
|
|
|
|
|
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
|
|
|
|
module WorkDataSource (
|
|
|
|
work,
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Haxl.Prelude
|
|
|
|
import Prelude ()
|
|
|
|
|
|
|
|
import Haxl.Core
|
|
|
|
import Haxl.DataSource.ConcurrentIO
|
|
|
|
|
|
|
|
import Control.Exception
|
|
|
|
import Data.Hashable
|
|
|
|
import Data.Typeable
|
|
|
|
|
2019-04-10 19:45:58 +03:00
|
|
|
work :: Integer -> GenHaxl u w Integer
|
2018-01-10 19:31:02 +03:00
|
|
|
work n = dataFetch (Work n)
|
|
|
|
|
|
|
|
data Work deriving Typeable
|
|
|
|
instance ConcurrentIO Work where
|
|
|
|
data ConcurrentIOReq Work a where
|
2018-02-01 18:26:57 +03:00
|
|
|
Work :: Integer -> ConcurrentIOReq Work Integer
|
2018-01-10 19:31:02 +03:00
|
|
|
|
|
|
|
performIO (Work n) = evaluate (sum [1..n]) >> return n
|
|
|
|
|
|
|
|
deriving instance Eq (ConcurrentIOReq Work a)
|
|
|
|
deriving instance Show (ConcurrentIOReq Work a)
|
|
|
|
|
|
|
|
instance ShowP (ConcurrentIOReq Work) where showp = show
|
|
|
|
|
|
|
|
instance Hashable (ConcurrentIOReq Work a) where
|
|
|
|
hashWithSalt s (Work n) = hashWithSalt s n
|